#导入包
import pandas as pd
import matplotlib.pyplot as plt
import os
%matplotlib inline
#定义路径
os.chdir('e:\\students\\Xiongh')
#打开excel文件
df=pd.read_excel('Mean_std.xls',sheetname='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
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()
python绘制多子图
最新推荐文章于 2024-12-19 14:32:38 发布