问题描述
是否有一种简单的方法将y轴标签放在绘图的右侧?我知道可以使用ax.yaxis.tick_right()
在刻度线标签上完成此操作,但是我想知道是否也可以在坐标轴标签上完成此操作.
Is there a simple way to put the y-axis label on the right-hand side of the plot? I know that this can be done for the tick labels using ax.yaxis.tick_right()
, but I would like to know if it can be done for the axis label as well.
想到的一个想法就是使用
One idea which came to mind was to use
ax.yaxis.tick_right()
ax2 = ax.twinx()
ax2.set_ylabel('foo')
但是,在保留y轴的范围的同时,将所有标签(刻度和轴标签)放置在右侧并没有达到预期的效果.简而言之,我想要一种将所有y轴标签从左向右移动的方法.
However, this doesn't have the desired effect of placing all labels (tick and axis labels) on the right-hand side, while preserving the extent of the y-axis. In short, I would like a way to move all the y-axis labels from the left to the right.
推荐答案
您似乎可以使用以下方法做到这一点:
It looks like you can do it with:
ax.yaxis.set_label_position("right")
ax.yaxis.tick_right()
请参见此处作为示例.
这篇关于matplotlib y轴标签在右侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!