Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the font size of ticks of matplotlib.pyplot.colorbar.ColorbarBase?

Tags:

matplotlib

I would like to know how to change the font size of ticks of ColorbarBase of matplotlib. The following lines are a relevant part in my analysis script, in which ColorbarBase is used.

import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
import matplotlib as mpl

axcb = fig.add_axes([0.9, 0.135, 0.02, 0.73])

cb = mpl.colorbar.ColorbarBase(axcb, norm=LogNorm(vmin=7e-5, vmax=1), cmap=plt.cm.CMRmap)
cb.set_label("Relative Photon Intensity", labelpad=-1, size=14)

I am using matplotlib ver 1.4.3 with Python 2.7 on OS X.

like image 803
Akira Okumura Avatar asked Mar 16 '15 10:03

Akira Okumura


People also ask

How do I change the Colorbar scale 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

You can change the tick size using:

font_size = 14 # Adjust as appropriate.
cb.ax.tick_params(labelsize=font_size)

See the docs for ax.tick_params here for more parameters that can be modified.

like image 121
Ffisegydd Avatar answered Oct 28 '22 18:10

Ffisegydd


Ffisegydd's answer works good, but if you are trying to increase the font size but some numbers disappear because of big size, you can do

cb = plt.colorbar()
for t in cb.ax.get_yticklabels():
     t.set_fontsize(20)
like image 39
Alejo Bernardin Avatar answered Oct 28 '22 18:10

Alejo Bernardin