我試圖在 X 軸上顯示年份,由條形表示的體積和由線表示的值。誰(shuí)能看到我哪里出錯(cuò)了?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貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超3個(gè)贊
你想傳遞X='Year'
到 plot 命令。
data1[['Year', 'Volume']].plot(x='Year',kind='bar', width = 0.5, color="navy") data1['Value'].plot(secondary_y=True, color='orange')
輸出:
添加回答
舉報(bào)
0/150
提交
取消