1
我正在研究一本關於matplotlib的電子書,我對雙軸的一個例子有疑問。 的代碼是這樣的:雙軸瑕疵標籤(matplotlib)
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0., np.e, 0.01)
y1 = np.exp(-x)
y2 = np.log(x)
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.plot(x, y1)
ax1.set_ylabel('Y values for exp(-x)')
ax2 = ax1.twinx() # this is the important function
ax2.plot(x, y2, 'r')
ax2.set_xlim([0, np.e])
ax2.set_ylabel('Y values for ln(x)')
ax2.set_xlabel('Same X for both exp(-x) and ln(x)')
plt.show()
結果是這樣的,在X標籤似乎丟失:
我運行Pycharm代碼。 是否有缺少標籤的原因?
感謝
這是......奇怪。我認爲這是來自代碼,它確保你不能以重疊的xlabels結束。 – tacaswell
我注意到我正在閱讀的這本書是在2009年出版的。也許在舊版本的matplotlib中,可以將標籤放在兩個軸上,然後這個更改,或許可以避免可能的衝突,正如您所說的那樣? – Antlab