Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python matplotlib decrease size of colorbar labels

I need your help! I have a plotting code which is the following:

fig = plt.figure() ax1 = fig.add_subplot(111)  imax1 = ax1.imshow(data,interpolation = 'nearest', origin = 'lower',cmap=cm.jet)#plot cbar = plt.colorbar(imax1, extend='neither', spacing='proportional',                 orientation='vertical', shrink=0.7, format="%.0f") cbar.set_label(r"ET [mm/month]", size=10)  titlestr = "Evapotranspiration in mm/month" plt.title(titlestr) #plt.xlabel("Longitude") #plt.ylabel("Latitude") imax1.set_clim(0,60) labels = [item.get_text() for item in ax1.get_xticklabels()] for ii in range(np.shape(labels)[0]):     labels[ii] = str(grid_lon[75*ii/np.shape(labels)[0]])  ax1.set_xticklabels(labels, rotation = 45, ha='right', size = 10)  labels = [item.get_text() for item in ax1.get_yticklabels()] for ii in range(np.shape(labels)[0]):     labels[ii] = str(grid_lat[75*ii/np.shape(labels)[0]])  ax1.set_yticklabels(labels, size = 10)  pngname = "./out/2d_"+variable+"_"+mm+".png" print "save ", pngname plt.savefig(pngname, dpi=None, facecolor='w', edgecolor='w',     orientation='portrait', papertype=None, format=None,     transparent=False, bbox_inches=None, pad_inches=0.1)   print "plot finished" 

I would like to set the label size of the colorbar labels (e.g. 0,10,20,...60) to size of 10 or smaller. This will probably go into the line "imax1.set_clim(0,60). Any ideas? I'd be also interested to print information of the imax1 object to command line. How could I do that? E.g. available attributes and functions of imax1.

I deeply appreciate your help!

like image 727
user1113953 Avatar asked Mar 09 '13 00:03

user1113953


People also ask

How do I scale a Colorbar in Matplotlib?

Use the matpltolib. pyplot. clim() Function to Set the Range of Colorbar in Matplotlib. The clim() function can be used to control the range of the colorbar by setting the color limits of the plot, which are used for scaling.


2 Answers

Aha! Found the answer here:

cbar.ax.tick_params(labelsize=10)  

P.S. Upvote that answer and give Paul some love!

like image 156
crayzeewulf Avatar answered Sep 20 '22 23:09

crayzeewulf


If you are here because you're trying to increase font size, but some numbers disappear because of big size with the above answer, you can do

cbar = plt.colorbar() for t in cbar.ax.get_yticklabels():      t.set_fontsize(20) 
like image 20
Alejo Bernardin Avatar answered Sep 18 '22 23:09

Alejo Bernardin