在pyplot中绘制带有两个y轴的图表

时间:2020-10-22 20:47:58

标签: python pandas matplotlib plot

我想在图表中绘制两个y轴。到目前为止,我可以绘制两个y轴,但在右侧绘制y轴,但是如何在相同的零值水平处更改正确的y轴呢?

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

0 个答案:

没有答案