How do I adjust (offset) colorbar title in matplotlib

前端 未结 2 1871
伪装坚强ぢ
伪装坚强ぢ 2021-02-03 22:59

Given the following code:

imshow(np.arange(16*16).reshape(16,16))
cb = colorbar()
cb.set_label(\"Foo\")
cb.set_ticks([0,255])

Which produces:

相关标签:
2条回答
  • 2021-02-03 23:38
    cb.set_label("Foo",horizontalalignment='right')
    

    The label control with this function is very poor...


    You could do:

    cb = colorbar()
    cb.set_ticks([0,255])
    ax = cb.ax
    ax.text(1.3,0.5,'Foo',rotation=90)
    
    0 讨论(0)
  • 2021-02-03 23:42
    cb.set_label("Foo", labelpad=-1)
    

    Negative labelpad values will move closer to the bar, positive away.

    0 讨论(0)
提交回复
热议问题