我试图在 X 轴上显示年份,由条形表示的体积和由线表示的值。谁能看到我哪里出错了?import numpy as npimport pandas as pdfrom matplotlib import pyplot as pltdata1 = pd.DataFrame({'Year' : [2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019], 'Volume' : [32, 35, 33, 36, 38, 39, 40, 42, 49, 47], 'Value' : [40, 41, 46, 44, 43, 42, 42, 45, 48, 52]})data1[['Year', 'Volume']].plot(kind='bar', width = 0.5, color="navy")data1['Value'].plot(secondary_y=True, color='orange')plt.show()
1 回答
DIEA
TA贡献1820条经验 获得超2个赞
你想传递X='Year'
到 plot 命令。
data1[['Year', 'Volume']].plot(x='Year',kind='bar', width = 0.5, color="navy") data1['Value'].plot(secondary_y=True, color='orange')
输出:
添加回答
举报
0/150
提交
取消