2

I want to plot two y-axes in a chart. So far I can plot two y-axes but the y-axes at right hand side but how to change the right y-axes at the same level of the zero?

dict_one = {'date': [pd.Timestamp('20150720'),pd.Timestamp('20160720'),pd.Timestamp('20170720'),pd.Timestamp('20180720'),pd.Timestamp('20190720'),pd.Timestamp('20200720')],
            'BKNG': [15.22, 6.36, 5.05, 5, 9.3641, -3],
            'MCD' : [25.22, 11.36, 7.05, 9, 8.3641, -6],
            'YUM' : [52.22, 21.36, 25.05, 26, 21.3641, -1000]
    
}

df = pd.DataFrame(dict_one)
df['date'] = df['date'].dt.year
df.set_index('date',inplace=True)

df.plot(figsize= (20,8), kind='bar',secondary_y='YUM')

output

janicewww
  • 323
  • 1
  • 10
  • 1
    See [Matplotlib axis with two scales shared origin](https://stackoverflow.com/questions/10481990/matplotlib-axis-with-two-scales-shared-origin) – JohanC Oct 22 '20 at 21:23
  • 1
    See [Python - dual y axis chart, align zero](https://stackoverflow.com/questions/51034573/python-dual-y-axis-chart-align-zero) how it can work together with pandas. – JohanC Oct 22 '20 at 21:31
  • 1
    [This](https://matplotlib.org/2.2.5/gallery/api/two_scales.html) may be of help to you. – Gonçalo Peres May 29 '21 at 07:23

0 Answers0