![](/img/trans.png)
[英]Matplotlib: How to display and position 2 YAxis BOTH on the Left side of my graph
[英]How to display yaxis on both side using matplotlib 0.99?
我想在兩邊都顯示yaxis。 在matplotlib 1.2中,我可以使用以下代碼:
ax.tick_params(labelright = True)
但是,在matplotlib 0.99中沒有用於方法的tick_params
。 有沒有簡單的方法可以在0.99中做到這一點? TKS
編輯我得到了這個解決方案,然后是@Brian Cain
ax2 = ax1.twinx()
ax2.set_yticks(ax1.get_yticks())
ax2.set_yticklabels([t.get_text() for t in ax1.get_yticklabels()])
這是來自matplotlib
文檔的示例,每個Y軸上的比例不同。 如果願意,可以使用相同的音階。
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(111)
t = np.arange(0.01, 10.0, 0.01)
s1 = np.exp(t)
ax1.plot(t, s1, 'b-')
ax1.set_xlabel('time (s)')
# Make the y-axis label and tick labels match the line color.
ax1.set_ylabel('exp', color='b')
for tl in ax1.get_yticklabels():
tl.set_color('b')
ax2 = ax1.twinx()
s2 = np.sin(2*np.pi*t)
ax2.plot(t, s2, 'r.')
ax2.set_ylabel('sin', color='r')
for tl in ax2.get_yticklabels():
tl.set_color('r')
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.