python 柱状图_python多柱状图

#导入相应的包
import pandas as pd
import matplotlib.pyplot as plt
import os
%matplotlib inline
os.chdir('E://xh/python代码')#设置路径

df=pd.read_excel('Mean_std.xls',sheet_name='Sheet3')

数据筛选
y1=df['Mean'].loc[0:5]
y2=df['Mean'].loc[6:11]
y3=df['Mean'].loc[12:17]
y4=df['Mean'].loc[18:23]
er1=df['std'].loc[0:5]
er2=df['std'].loc[6:11]
er3=df['std'].loc[12:17]
er4=df['std'].loc[18:23]

x=(1,2,3,4,5,6)
#定义画布
fig=plt.figure(dpi=200)
#定义多子图
fig,ax=plt.subplots(2,2,dpi=200,figsize=(25,20))
plt.subplots_adjust(hspace=0.2,wspace=0.2)
labels1=['Gansu26','Gansu45','Gansu60','Gansu85','GansuCurrent','Gansumid']
labels2=['Qinghai26','Qinghai45','Qinghai60','Qinghai85','QinghaiCurrent','Qinghaimid']
labels3=['Sichuan26','Sichuan45','Sichuan60','Sichuan85','SichuanCurrent','Sichuanmid']
labels4=['Tibet26','Tibet45','Tibet60','Tibet85','TibetCurrent','Tibetmid']
#yerr:误差棒 tick_label X坐标修改为其他
ax[0][0].bar(x,y1,yerr=er1,tick_label=labels1,width=0.5)
ax[0][1].bar(x,y2,yerr=er2,tick_label=labels2,width=0.5)
ax[1][0].bar(x,y3,yerr=er3,tick_label=labels3,width=0.5)
ax[1][1].bar(x,y4,yerr=er4,tick_label=labels4,width=0.5)
plt.show()

a5adc77dddfdc972b73123b914300d4b.png
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值