【发布时间】:2021-05-22 13:15:00
【问题描述】:
我正在尝试绘制:线图和条形图在同一个图上,但线没有出现。代码如下:
df = pd.read_csv('cars.csv')
df['Price'] = pd.to_numeric(df['Price'])
m = df.groupby(['Brand', 'Year'])['Price'].mean()
s = df.groupby('Year').Price.mean()
ax = m.unstack('Brand').plot.bar()
s.plot(x=ax.get_xticks('Year'), ax=ax, kind='line', label='Mean price')
y_formatter = ScalarFormatter(useOffset=False)
plt.show()
我在这里做错了什么?
【问题讨论】:
标签: python pandas matplotlib bar-chart line-plot