Python:如何从 pandas 图中叠加 2 个条形图 [英] Python: How to overlay 2 bar plots from pandas plot
本文介绍了Python:如何从 pandas 图中叠加 2 个条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用相同的 x-xis 叠加 2 个条形图.我有一个包含此数据的数据框:
I want to superimpose 2 bar plots with same x-xis. I have a dataframe with this data:
df = pd.DataFrame({'a':[1,2,3,1,2,2,2],
'b':[1,1,1,3,2,2,2]})
我可以为a和b绘制2个直方图:
I can plot 2 histogram plots for a and b:
df['a'].value_counts().plot(kind = 'bar')
df['b'].value_counts().plot(kind = 'bar')
如何将其中一个叠加到另一个上?
How can i superimpose one of them on the other ?
我正在寻找的不相关图表格式的示例:
Example of an unrelated chart format that im looking for:
推荐答案
使用 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 个条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文