Python Matplotlib使用翻转标签将y轴放置在右侧

Python Matplotlib使用翻转标签将y轴放置在右侧,python,matplotlib,Python,Matplotlib,我希望y轴位于绘图的右侧,但标签也朝向正确的方向。有许多答案可以解释第一部分,具体如下: import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot() ax.plot([1,2,3,4,5]) ax.set_ylabel("RHS") ax.yaxis.set_label_position("right") ax.yaxis.tick_right() plt.show()

我希望y轴位于绘图的右侧,但标签也朝向正确的方向。有许多答案可以解释第一部分,具体如下:

import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot()
ax.plot([1,2,3,4,5])
ax.set_ylabel("RHS")
ax.yaxis.set_label_position("right")
ax.yaxis.tick_right()
plt.show()
这将产生以下结果:

但这里的问题是,右边的yaxis标签朝外,理想情况下,我希望它朝内,如下所示:


在此方面的任何帮助都将不胜感激

只需在通话中添加以下KWARG:

给出了预期输出:

如果要在设置标签后修改标签,也可以执行以下操作:

yl = ax.set_ylabel("RHS")
ax.yaxis.set_label_position("right")
yl.set_rotation(50)
# do some other stuff

然后别忘了调用
plt.draw()
使其生效。您可能需要查看实例属性。

谢谢,这回答了我的问题。如果您碰巧知道,是否有一种方法可以在设置ylabel后修改轴的ylabel的旋转,而无需重置ylabel?类似于ax.ylabel.rotation=-90的东西?
yl = ax.set_ylabel("RHS")
ax.yaxis.set_label_position("right")
yl.set_rotation(50)
# do some other stuff