条形图与直方图很相似,但是条形图x轴表示的不是数值而是类别。
bar(x, height, *, align=’center’, **kwargs)
bar(x, height, width, *, align=’center’, **kwargs)
bar(x, height, width, bottom, *, align=’center’, **kwargs)
#位置,高,宽,对齐方式algin,
简单条形图
index=[0,1,2,3,4]
values=[5,7,3,4,6]
std1=[0.8,1.0,0.4,0.9,1.3]
plt.bar(index,values,yerr=std1,error_kw={
'ecolor':'r','capsize':6},label='first')
#yerr接收标准差,常常与erroe_kw一起使用,ecolor指定误差线颜色,capsize指定误差线两头横线的宽度
plt.legend(loc=2)
plt.xticks(index,['a','b','c','d','e'])
水平条形图
import numpy
import matplotlib.pyplot as plt
import matplotlib
from matplotlib import cm
index=[0,1,2,3,4]
values=sorted([5,7,3,4,6])
std1=[0.8,1.0,0.4,0.9,1.3]
col=cm.jet(numpy.array(values