我想制作3个具有多个y列和单个x列的子图。
可以找到我正在使用的数据File Link
我已经使用groupby来生成要使用的数据
East = SalesData.loc[SalesData['Region'] == 'East']
West = SalesData.loc[SalesData['Region'] == 'West']
Central = SalesData.loc[SalesData['Region'] == 'Central']
Sales_comparison_East = East[['Sales2015', 'Sales2016','Tier']].groupby(['Tier']).sum().reset_index()
Sales_comparison_West = West[['Sales2015', 'Sales2016','Tier']].groupby(['Tier']).sum().reset_index()
Sales_comparison_Central = Central[['Sales2015', 'Sales2016','Tier']].groupby(['Tier']).sum().reset_index()
我用来绘制子图的代码是
# Formatting the plot size as per requirement
plt.rcParams['figure.figsize'] = (12, 4)
# Plotting the 1st plot
plt.subplot(1, 3, 1)
plt.xlabel('Tier')
plt.ylabel('Sales')
plt.title('Central')
plt.bar(Sales_comparison_Central.Tier,
Sales_comparison_Central[['Sales2015','Sales2016']])
# Plotting the 2nd plot
plt.subplot(1, 3, 2)
plt.xlabel('Tier')
plt.ylabel('Sales')
plt.title('East')
plt.bar(Sales_comparison_East.Tier,
Sales_comparison_East[['Sales2015','Sales2016']])
# Plotting the 3rd plot
plt.subplot(1, 3, 3)
plt.xlabel('Tier')
plt.ylabel('Sales')
plt.title('West')
plt.bar(Sales_comparison_West.Tier,
Sales_comparison_West[['Sales2015','Sales2016']])
plt.tight_layout()
plt.show()
我正在寻找的输出类似于 Image output
该代码提供了一个错误,我在做什么错??