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:
How do I adjust the colorbar text "Foo" so that it is offset to the left, betwen the 0 and 255, closer to the colorbar, reducing the un-needed whitespace?
Method 2: Change and Rotate the position of the label To rotate the colorbar labels we will use set_xticklabels() and set_yticklabels() methods for horizontal and vertical.
To decrease colorbar width in Matplotlib, we can use shrink in colorbar() method.
To have one color bar for all subplots with Python, we can use matplotlib's subplots_adjust and colorbar methods. to call subplots_adjust on the fig subplot with the right argument to adjust the position of the subplots.
The colorbar() function in pyplot module of matplotlib adds a colorbar to a plot indicating the color scale. Syntax:matplotlib.pyplot.colorbar(mappable=None, cax=None, ax=None, **kwarg) Parameters: ax: This parameter is an optional parameter and it contains Axes or list of Axes.
cb.set_label("Foo", labelpad=-1)
Negative labelpad values will move closer to the bar, positive away.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With