I would like X axis labels on factorplots (which are dates) to be vertical up the screen rather than horizonal (as horizontal takes up too much space).
Asked
Active
Viewed 1,975 times
0
-
3possible duplicate of [Rotate label text in seaborn factorplot](http://stackoverflow.com/questions/26540035/rotate-label-text-in-seaborn-factorplot) – mwaskom Dec 08 '14 at 20:08
1 Answers
0
This is, IMO, the stickiest point with matplotlib. You have to rotate each label individually.
I always keep this function handy:
def rotateTickLabels(ax, rotation, which, rotation_mode='anchor', ha='right'):
axes = []
if which in ['x', 'both']:
axes.append(ax.xaxis)
elif which in ['y', 'both']:
axes.append(ax.yaxis)
for axis in axes:
for t in axis.get_ticklabels():
t.set_horizontalalignment(ha)
t.set_rotation(rotation)
t.set_rotation_mode(rotation_mode)
So then you use it like this:
import matploltib.pyplot as plt
fig, ax = plt.subplots()
# ... plot stuff
rotateTickLabels(ax, 30, 'x')

Paul H
- 65,268
- 20
- 159
- 136