Change fontsize of colorbars in matplotlib

colorbar, matplotlib, python-2.7

Solution

use `cbar.ax.tick_params(labelsize=10)`

From here and here

Problem

I am having difficulty adjusting the font size of the ticks on the colorbar in the following code. ``` fig = plt.figure(figsize=(10,6)) ax = fig.add_subplot(111) im = ax.pcolor(np.ma.masked_invalid(np.roll(lon, -1100, axis=1)[:2100, :3500]), np.ma.masked_invalid(np.roll(lat, -1100, axis=1)[:2100, :3500]), np.ma.masked_invalid(np.roll(np.absolute(zeta_Mar), -1100, axis=1)[:2100, :3500]), cmap='Reds', norm=colors.LogNorm(vmin=1e-6, vmax=1e-4)) ax.set_xlabel('Longitude', fontsize=14) ax.set_xlabel('Latitude', fontsize=14) cbar_axim = fig.add_axes([0.95, 0.15, 0.03, 0.7]) cbar = fig.colorbar(im, cax=cbar_axim, ticks=[1e-6, 1e-5, 1e-4]) cbar.set_ticklabels([r'$-10^{-6}$', r'$10^{-5}$', r'$10^{-4}$']) cbar.set_label(r'$\zeta\ [s^{-1}]$', fontsize=16) plt.show() ``` Could anyone tell me the correct syntax to include the fontsize argument?

Original source

Related problems