我想在同一个图上绘制一条线和一条线。这是什么工作,什么不工作。有人会解释为什么吗?熊猫在线的阴谋条形图
什么行不通:
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