我想在同一個圖上繪製一條線和一條線。這是什麼工作,什麼不工作。有人會解釋爲什麼嗎?熊貓在線的陰謀條形圖
什麼行不通:
df = pd.DataFrame({'year':[2001,2002,2003,2004,2005], 'value':[100,200,300,400,500]})
df['value1']= df['value']*0.4
df['value2'] = df['value']*0.6
fig, ax = plt.subplots(figsize = (15,8))
df.plot(x = ['year'], y = ['value'], kind = 'line', ax = ax)
df.plot(x = ['year'], y= ['value1','value2'], kind = 'bar', ax = ax)
但不知何故,當我在第一個情節刪除x=['year']
工作:
fig, ax = plt.subplots(figsize = (15,8))
df.plot(y = ['value'], kind = 'line', ax = ax)
df.plot(x = ['year'], y= ['value1','value2'], kind = 'bar', ax = ax)
的可能的複製[熊貓情節不覆蓋(http://stackoverflow.com/questions/42948576/pandas-plot-does-not-overlay) – ImportanceOfBeingErnest
[這個問題](HTTP:/ /stackoverflow.com/questions/42813890/python-making-combined-bar-and-line-plot-with-secondary-y-axis)也可能是有趣的。 – ImportanceOfBeingErnest