嗨,我在数据框 groupby 之后绘制子条形图时遇到了一些问题
post groupby,数据如下:
我尝试了以下方法来创建条形图。
df_temp[df_temp.index =='ABC'].unstack().plot.bar(figsize=(10,2))
如何绘制条形图,其中 x 轴是日期,y 轴是计数,每一行(ABC 和 EFG)都是它自己的子图(垂直堆叠)
下面的例子
感谢您的帮助!
答案 0 :(得分:2)
感谢@r-beginnners
#remove the multi-level column
df.columns = df.columns.droplevel()
#plot the sub-plots
# if y-axis scale to be the same, use sharey=True
df.T.plot(subplots=True, layout=(2,1), kind='bar', sharey=True)