There are many “right” answers here, but I will add one more, because I think some details are omitted from several. The OP requested a rotation of 90 degrees, but I will change it by 45 degrees, because when you use an angle that is not zero or 90, you must also change the horizontal alignment; otherwise, your shortcuts will be off-center and a little misleading (and I assume that many people who come here want to rotate the axes by something other than 90).
The simplest / smallest code
Option 1
plt.xticks(rotation=45, ha='right')
As mentioned earlier, this may not be desirable if you prefer an object oriented approach.
Option 2
Another quick way (it is for date objects, but seems to work on any shortcut; I doubt this is recommended):
fig.autofmt_xdate(rotation=45)
fig you usually get from:
fig = plt.figure()fig, ax = plt.subplots()fig = ax.figure
Object Oriented / Work directly with ax
Option 3a
If you have a list of tags:
labels = ['One', 'Two', 'Three'] ax.set_xticklabels(labels, rotation=45, ha='right')
Option 3b
If you want to get a list of labels from the current chart:
Option 4
Similar to the above, but instead manually crawl.
for label in ax.get_xticklabels(): label.set_rotation(45) label.set_ha('right')
Option 5
We still use pyplot (like plt ) here, but it is object oriented because we are changing the property of a particular ax object.
plt.setp(ax.get_xticklabels(), rotation=45, ha='right')
Option 6
This option is simple, but, AFAIK, you cannot set the label to align horizontally this way, so another option might be better if your angle is not 90.
ax.tick_params(axis='x', labelrotation=45)
Edit: There is a discussion of this exact “error”, and a fix is potentially planned for v3.2.0 : https://github.com/matplotlib/matplotlib/issues/13774