matplotlib y-axis label on right side

强颜欢笑 提交于 2019-12-03 04:09:06
Gerrat

It looks like you can do it with:

ax.yaxis.set_label_position("right")
ax.yaxis.tick_right()

See here for an example.

Gourav Mahapatra

If you would like to follow the example given in matplotlib and create a figure with labels on both sides of the axes but without having to use the subplots() function, here is my solution :

from matplotlib import pyplot as plt
import numpy as np

ax1 = plt.plot()
t = np.arange(0.01, 10.0, 0.01)
s1 = np.exp(t)
plt.plot(t,s1,'b-')
plt.xlabel('t (s)')
plt.ylabel('exp',color='b')

ax2 = ax1.twinx()
s2 = np.sin(2*np.pi*t)
ax2.plot(t, s2, 'r.')
plt.ylabel('sin', color='r')
plt.show()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!