Rotation of colorbar tick labels in matplotlib Rotation of colorbar tick labels in matplotlib numpy numpy

Rotation of colorbar tick labels in matplotlib


If you're happy with tick locations and labels and only want to rotate them:

cbar.ax.set_xticklabels(cbar.ax.get_xticklabels(), rotation='vertical')


You can use cbar.ax.set_xticklabels to change the rotation (or set_yicklabels if you had a vertical colorbar).

cbar.ax.set_xticklabels(clevs1[::1],rotation=90)

enter image description here

EDIT:

To set the ticks correctly, you can search for where in your clevs1 array the first tick should be using np.argmin, and use that to index clevs1 when you set_xticklabels:

tick_start = np.argmin(abs(clevs1-clevs[0]))cbar.ax.set_xticklabels(clevs1[tick_start:],rotation=90)

enter image description here


This is the idiomatic way to rotate tick labels as of Matplotlib 3.4 (and very likely earlier versions too)

cbar.ax.tick_params(rotation=45)