Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 基于matplotlib的Pandas groupby直方图_Python_Pandas_Matplotlib - Fatal编程技术网

Python 基于matplotlib的Pandas groupby直方图

Python 基于matplotlib的Pandas groupby直方图,python,pandas,matplotlib,Python,Pandas,Matplotlib,我有数据FRME,我在两列上对其执行groupby: ax = df_all.groupby(['Component', 'SubComponent' ])['SubComponent'].count() 给我这个: -------------------------------------------------- | Component | SubComponent| | --------------------------------------

我有数据FRME,我在两列上对其执行groupby:

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)