我有以下 df
| 指數 | 活著的過去和未來 | 活著的過去 | % |
|---|---|---|---|
| 1/1/2020 | 800 | 1000 | 0.8 |
| 1/2/2020 | 200 | 400 | 0.5 |
| 1/3/2020 | 300 | 300 | 1.0 |
| 1/4/2020 | 400 | 800 | 0.5 |
| 1/5/2020 | 500 | 2000年 | 0.25 |
這是我用來繪制面積圖的代碼
df.plot.area(stacked=False)

有沒有辦法讓前兩列作為面積圖,第三列畫成一條線?面積和線是否有可能具有不同的 y 軸(左和右),因為它們具有不同的量級?
uj5u.com熱心網友回復:
嘗試:
# plot area with first two columns
ax = df.iloc[:,:2].plot.area()
# line plot with 3rd column
df.plot(y='%', secondary_y=True, ax=ax)
輸出:

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/340435.html
標籤:Python 熊猫 matplotlib 阴谋
