我有兩個子圖,但我希望它們都共享相同的 Xlabel。每個子圖都來自一個單獨的資料框。問題是,即使我使用了sharex=True. 每個子圖都有自己的 xlabel,來自資料框列名。
代碼:
fig,ax = plt.subplots(1,2, sharex=True)
df1.plot.line(ax=ax[0],x='X',y='Y',linestyle='--',
marker='s', color='tab:orange',legend=False, sharex=True)
df2.plot.line(ax=ax[1],x='X',y='Y',linestyle='--',
marker='s', color='tab:blue',legend=False, sharex=True)
plt.xlabel("Epoch")
plt.show()
uj5u.com熱心網友回復:
你期待這樣的結果嗎:

如果是,您需要更正:
fig,ax = plt.subplots(1,2, sharex=True)
經過:
fig,ax = plt.subplots(2,1, sharex=True)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/333434.html
標籤:Python 熊猫 matplotlib
上一篇:選擇與字串包含完全匹配的行
下一篇:如何在熊貓中將字串替換為int?
