Rotate tick labels in subplot (Pyplot, Matplotlib, gridspec)

Just wanted to add another solution that I found on the matplotlib git discussion page:

ax[your_axis].tick_params(axis='x', rotation=90)

You can specify the axis you want by passing in the specific paramater. The advantage of this method over the accepted answer is that you can control which axis this change is applied to. Other parameters can be found here


You can set the rotation property of the tick labels with this line:

plt.setp(axa.xaxis.get_majorticklabels(), rotation=45)

setp is a utility function to set a property of multiple artists (all ticklabels in this case).

BTW: There is no difference between a 'normal' and a subplot in matplotlib. Both are just Axes objects. The only difference is the size and position and the number of them in the same figure.


You can do it in multiple ways:

Here is one solution making use of tick_params:

ax.tick_params(labelrotation=45)

Here is another solution making use of set_xticklabels:

ax.set_xticklabels(labels, rotation=45)

Here is a third solution making use of set_rotation:

for tick in ax.get_xticklabels():
    tick.set_rotation(45)