x = data.groupby([‘brand’,‘月份’]).sum()[‘counts’].to_frame()
x = x[x[‘counts’]>=1000]
x.head()
x = x.rename(columns={‘counts’:‘month’})
tmp = x.unstack()
tmp
fonts = fm.FontProperties(fname=‘simsun.ttc’) # 设置字体
plt.figure(figsize=(100,5))
tmp.plot(kind=‘bar’,width= 1)
plt.xticks(fontproperties=fonts,rotation=45)
plt.legend(loc=2, bbox_to_anchor=(1.05,1.0)) ##设置ax4中legend的位置,将其放在图外
plt.show()
fonts = fm.FontProperties(fname=‘simsun.ttc’) # 设置字体
转置之后再绘制
(tmp.T).plot(kind=‘bar’,width= 1)
plt.xticks(fontproperties=fonts,rotation=45)
plt.xlabel(xlabel=’’,fontproperties=fonts)
plt.legend(loc=2, bbox_to_anchor=(1.05,1.0),prop=fonts)
plt.show()