How to print Y axis label horizontally in a matplotlib / pylab chart?
It is very simple. After plotting the label, you can simply change the rotation:
from matplotlib import pyplot as pltplt.ion()plt.plot([1,2,3])h = plt.ylabel('y')h.set_rotation(0)plt.draw()
Alternatively, you can pass the rotation as an argument, i.e
plt.ylabel('y',rotation=0)
Expanding on the accepted answer, when we work with a particular axes object ax
:
ax.set_ylabel('abc', rotation=0, fontsize=20, labelpad=20)
Note that often the labelpad
will need to be adjusted manually too — otherwise the "abc" will intrude onto the plot.
From brief experiments I'm guessing that labelpad
is the offset between the bounding box of the tick labels and the y-label's centre. (So, not quite the padding the name implies — it would have been more intuitive if this was the gap to the label's bounding box instead.)