Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib - Title upon one `colobar`

I need to add some text just upon one colobar to have a title for it. Is it possible ?

Here is one starting code coming from this post.

from matplotlib.pylab import *
import matplotlib.cm as cm

min_val = 0
max_val = 1

# See : http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps
my_cmap = cm.get_cmap('jet') # or any other one
norm = matplotlib.colors.Normalize(min_val, max_val) # the color maps work for [0, 1]

cmmapable = cm.ScalarMappable(norm, my_cmap)
cmmapable.set_array(range(min_val, max_val))

figure()
ax = gca()

cbar = colorbar(cmmapable, ticks=[0, 1])
cbar.ax.set_yticklabels(['Min', 'Max'])

show()

1 Answers

set_title should do what you want (doc)

cbar.ax.set_title('title')
like image 148
tacaswell Avatar answered Apr 23 '26 00:04

tacaswell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!