How to give Matplolib imshow plot colorbars a label

Elliot picture Elliot · Dec 11, 2013 · Viewed 8.2k times · Source

We can give x and y axes labels for the main axes. Is there any way to similarly give a color bar a label? Alternately, is there any way to append a unit to one or more colorbar ticks?

Answer

qmorgan picture qmorgan · Dec 13, 2013

Like many axis objects, colorbar() has a set_label() method:

cbar = fig.colorbar(heatmap) 
cbar.set_label('Label name',size=18)