How to print Y axis label horizontally in a matplotlib / pylab chart?

前端 未结 2 1078
不知归路
不知归路 2020-12-08 12:57

I\'m creating very simple charts with matplotlib / pylab Python module. The letter \"y\" that labels the Y axis is on its side. You would expect this if the label was longer

2条回答
  •  一向
    一向 (楼主)
    2020-12-08 13:33

    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.)

提交回复
热议问题