条形图: ●以长方形的长度为变量的统计图表 ●用来比较多个项目分类的数据大小 ●通常利用于较小的数据集分析 ●例如不同季度的销量,不同国家的人口等 函数:
pyplot.bar(x, height, width=0.8, bottom=None, *, align='center', data=None, **kwargs)x:条形图的x坐标 height:条形图的高 width:条形图的宽,默认0.8 bottom:基座的y坐标 align:对齐,{‘center’,‘edge’},默认值:‘center’
center:使基准在x位置居中edge:对齐的左边缘条s的的X位置*data:None 其他参数
color:条形图的颜色edgecolor:条形边缘的颜色out:
in:
pl=plt.bar(x=0,bottom=index,width=y,color='red',height=0.5,orientation='horizontal')#orientation='horizontal'水平显示 #等同于pl=plt.barh(index,width=y,color='red',height=0.5)(具体可百度)out:
in:
index=np.arange(4) sales_BJ=[52,55,63,53] sales_SH=[44,66,55,41] bar_width=0.3 pl=plt.bar(index,height=sales_BJ,width=bar_width,color='b') pl=plt.bar(index+bar_width,height=sales_SH,width=bar_width,color='r')#要点在index+bar_width这个位置,不然两者会重叠out:
in:
index=np.arange(4) sales_BJ=[52,55,63,53]#北京销量 sales_SH=[44,66,55,41]#上海销量 bar_width=0.3 pl=plt.bar(index,height=sales_BJ,width=bar_width,color='b') pl=plt.bar(index,height=sales_SH,width=bar_width,color='r',bottom=sales_BJ)#要点bottom=sales_BJ,从北京的销量开始out: