I have the following df
index | Alive Past & Future | Alive Past | % |
---|---|---|---|
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 |
Here is the code I am using to draw an area chart
df.plot.area(stacked=False)
Is there a way to make the first 2 columns be as an area chart and the third column be drawn as a line? Also is it possible that the areas and the line have different y-axis (left and right) as they have different magnitudes?
CodePudding user response:
Try:
# 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)
Output: