In matplotlib, I want to change the font properties for a colorbar
label. For example I want the label to appear bold.
Here is some example code:
from matplotlib.pylab import *
pcolor(arange(20).reshape(4,5))
cb = colorbar(label='a label')
and the result, where I want "a label" to appear bold:
All other answers on this site only answer how to change ticklabels
or change all fonts in general (via modification of the matplotlibrc
file)
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.
Plot x data points using plot() method. To change the font size of the scale in matplotlib, we can use labelsize in the ticks_params()method. To display the figure, use show() method.
This two-liner can be used with any Text property (http://matplotlib.org/api/text_api.html#matplotlib.text.Text)
cb = plt.colorbar()
cb.set_label(label='a label',weight='bold')
I agree with francesco, but even shorten to one line:
plt.colorbar().set_label(label='a label',size=15,weight='bold')
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