Python 基于matplotlib的Pandas groupby直方图
我有数据FRME,我在两列上对其执行groupby:Python 基于matplotlib的Pandas groupby直方图,python,pandas,matplotlib,Python,Pandas,Matplotlib,我有数据FRME,我在两列上对其执行groupby: ax = df_all.groupby(['Component', 'SubComponent' ])['SubComponent'].count() 给我这个: -------------------------------------------------- | Component | SubComponent| | --------------------------------------
ax = df_all.groupby(['Component', 'SubComponent' ])['SubComponent'].count()
给我这个:
--------------------------------------------------
| Component | SubComponent| |
--------------------------------------------------
|A |First | 1|
--------------------------------------------------
| |Second | 10|
--------------------------------------------------
| |Third | 6|
--------------------------------------------------
|B |First | 8|
--------------------------------------------------
| |Second | 5|
--------------------------------------------------
| |Third | 17|
--------------------------------------------------
现在我想做一个柱状图。
每个条形图都是组件,每个组件都划分在子组件上,显示具有不同颜色的每个子组件的出现次数
使用matplotlib.pyploy是否有简单的方法来实现它
谢谢,
Subm您可以与以下设备一起使用:
注意:
您可能知道为什么我无法使用:plt.figure(figsize=(10,8))更改此绘图的大小吗?请尝试
ax.unstack().plot.bar(stacked=True,figsize=(10,8))
print (ax.unstack())
SubComponent First Second Third
Component
A 1 4 15
B 6 2 1
ax.unstack().plot.bar(stacked=True)
print (ax.unstack(0))
Component A B
SubComponent
First 1 6
Second 4 2
Third 15 1
ax.unstack(0).plot.bar(stacked=True)