matplotlib_带误差棒的条形图

 

import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']
x=np.arange(5)
y=[100,68,79,91,82]
err=[7,2,6,10,5]
err_attr={"elinewidth":2,"ecolor":"black","capsize":3}
plt.bar(x,y,color="c",width=0.6,yerr=err,error_kw=err_attr,tick_label=list("ABCDE"))
plt.show()

import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']
x=np.arange(5)
y=[100,68,79,91,82]
err=[7,2,6,10,5]
err_attr={"elinewidth":2,"ecolor":"black","capsize":3}
plt.barh(x,y,color="c",height=0.6,xerr=err,error_kw=err_attr,tick_label=list("ABCDE"))
plt.show()

import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']
x=np.arange(5)
y1=[100,68,79,91,82]
y2=[120,70,75,78,85]
err1=[7,2,6,10,5]
err2=[5,1,6,8,9]
err_attr={"elinewidth":2,"ecolor":"black","capsize":3}
bar_width=0.4
plt.bar(x,y1,color="#87CEEB",yerr=err1,error_kw=err_attr,width=bar_width)
plt.bar(x+bar_width,y2,color="#CD5C5C",yerr=err1,error_kw=err_attr,width=bar_width)
plt.xticks(x+bar_width/2,labels=["A","B","C","D","E"])
plt.legend([2010,2011])
plt.show()

import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']
x=np.arange(5)
y1=[100,68,79,91,82]
y2=[120,70,75,78,85]
err1=[7,2,6,10,5]
err2=[5,1,6,8,9]
err_attr={"elinewidth":2,"ecolor":"black","capsize":3}
bar_width=0.4
plt.bar(x,y1,color="#87CEEB",yerr=err1,error_kw=err_attr,width=bar_width)
plt.bar(x,y2,bottom=y1,color="#CD5C5C",yerr=err1,error_kw=err_attr,width=bar_width)
plt.xticks(x,labels=["A","B","C","D","E"])
plt.legend([2010,2011])
plt.show()

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值