【发布时间】:2021-06-16 09:20:24
【问题描述】:
我正在尝试在同一张图上绘制一个条形图和一条线形图。这是有效的和无效的。有人能解释一下为什么吗?
什么不起作用:
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)
【问题讨论】:
-
This question 可能也很有趣。
标签: python pandas matplotlib