在matplotlib中更改颜色条的字体大小

问题描述:

在以下代码中,我很难调整颜色栏上刻度线的字体大小.

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()

有人可以告诉我包含fontsize参数的正确语法吗?

Could anyone tell me the correct syntax to include the fontsize argument?

使用 cbar.ax.tick_params(labelsize = 10)

此处 查看更多