10

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?

Elliot
  • 5,211
  • 10
  • 42
  • 70
  • See here: http://stackoverflow.com/questions/6567724/matplotlib-so-log-axis-only-has-minor-tick-mark-labels-at-specified-points-also/6568248#6568248 – qmorgan Dec 11 '13 at 20:50
  • 2
    In short, `cbar = fig.colorbar(heatmap)` `cbar.set_label('Label name',size=18)` – qmorgan Dec 11 '13 at 20:51
  • @qmorgan You should post that as an answer. There is enough other stuff going on in the linked question it is worth having a simple answer. – tacaswell Dec 12 '13 at 15:47
  • @tcaswell OK, good to know! I'm still learning the etiquette of what should be answers and what should be comments - is this documented somewhere? – qmorgan Dec 13 '13 at 04:32

2 Answers2

7

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

cbar = fig.colorbar(heatmap) 
cbar.set_label('Label name',size=18)
qmorgan
  • 4,794
  • 2
  • 19
  • 14
  • Doesn't work. "Object has no attribute 'set_label'". – Elliot Dec 17 '13 at 16:17
  • At least for current versions of Matplotlib it should: [http://matplotlib.org/api/colorbar_api.html#matplotlib.colorbar.ColorbarBase.set_label] – rerx Mar 31 '14 at 22:39
0

You use annotate to place text just about anywhere and add an arrow to what it refers to see some examples here.

Steve Barnes
  • 27,618
  • 6
  • 63
  • 73