Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change font properties of a matplotlib colorbar label?

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:

output plot

All other answers on this site only answer how to change ticklabels or change all fonts in general (via modification of the matplotlibrc file)

like image 509
thengineer Avatar asked Apr 19 '14 16:04

thengineer


People also ask

How do you change the color bar label in Matplotlib?

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.

How do I change the font of a graph in Matplotlib?

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.


2 Answers

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')
like image 169
francesco Avatar answered Oct 19 '22 19:10

francesco


I agree with francesco, but even shorten to one line:

plt.colorbar().set_label(label='a label',size=15,weight='bold')
like image 18
Q-man Avatar answered Oct 19 '22 19:10

Q-man