我想知道如何制作多个条形图。
我想要的是在分开的两个条形图上显示实际价格和折扣价格的最低、最高价格。
起初,我只是尝试使用此代码制作图表
df.plot(kind='bar', y='actual_price', stacked=False)
但是这个只显示一张关于实际价格的最小值和最大值的图表。
我也尝试使用 fig, ax = plt.subplot(1,2, Figsize(10,10) 。 但总是报错
ax[0].bar(df.actual_price, stack=False)
如何解决这个问题? 如何知道高度是多少?那我必须更改数据框吗?
请分享您的意见。
谢谢
stack
您的数据集并使用 seaborn.catplot
:
import seaborn as sns
sns.catplot(df.stack([0, 1])
.rename_axis(['category', 'type', 'indicator'])
.reset_index(name='value'),
x='category', y='value', col='type', hue='indicator',
kind='bar')
输出:
可重复输入:
df = pd.DataFrame.from_dict({'index': ['Car', 'House', 'IT'],
'columns': [('actual_price', 'min'),
('actual_price', 'max'),
('discount_price', 'min'),
('discount_price', 'max')],
'data': [[10, 100, 50, 50], [5, 8, 3, 4], [1, 7, 1, 5]],
'index_names': [None],
'column_names': [None, None],
}, orient='tight')