matplotlib y轴标签在右侧 [英] matplotlib y-axis label on right side

查看:2619
本文介绍了matplotlib y轴标签在右侧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法将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()

请参见 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆