我想用相同的 x-xis 叠加 2 个条形图。 我有一个包含此数据的数据框:
df = pd.DataFrame({'a':[1,2,3,1,2,2,2],
'b':[1,1,1,3,2,2,2]})
我可以为 a 和 b 绘制 2 个直方图:
df['a'].value_counts().plot(kind = 'bar')
df['b'].value_counts().plot(kind = 'bar')
如何将其中一个叠加到另一个上?
最佳答案
使用width
和ax
参数:
ax = df['a'].value_counts().plot(kind='bar', color='blue', width=.75, legend=True, alpha=0.8)
df['b'].value_counts().plot(kind='bar', color='maroon', width=.5, alpha=1, legend=True)
输出:
关于Python:如何从 Pandas 图中叠加 2 个条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50011376/