import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm
#读取数据
#利用循环一次做四个图
for i in range(4):
data = pd.read_excel(r'C:\Users\Administrator\Desktop\图.xlsx',sheet_name = i)
std_table = data.groupby(by = '上层光截获').std() # 计算标准差
figdata = data.groupby(by = '上层光截获').mean() #计算均值
# 绘图
# 标记样式常用的值有(./,/o/v/^/s/*/D/d/x/>/h/H/1/2/3/4/_/|)
plt.errorbar(figdata.columns,figdata.loc['R1D1'],yerr=std_table.loc['R1D1'],fmt='k-o',lw = 2,ecolor='k',elinewidth=1,ms=7,capsize=3)
plt.errorbar(figdata.columns,figdata.loc['R1D2'],yerr=std_table.loc['R1D2'],fmt='k-x',lw = 2,ecolor='k',elinewidth=1,ms=7,capsize=3)
plt.errorbar(figdata.columns,figdata.loc['R1D3'],yerr=std_table.loc['R1D3'],fmt='k-d',lw = 2,ecolor='k',elinewidth=1,ms=7,capsize=3)
plt.errorbar(figdata.columns,figdata.loc['R2D1'],yerr=std_table.loc['R2D1'],fmt='k-s',lw = 2,ecolor='k',elinewidth=1,ms=7,capsize=3)
plt.errorbar(figdata.columns,figdata.loc['R2D2'],yerr=std_table.loc['R2D2'],fmt='k-p',lw = 2,ecolor='k',elinewidth=1,ms=7,capsize=3)
plt.errorbar(figdata.columns,figdata.loc['R2D3'],yerr=std_table.loc['R2D3'],fmt='k-^',lw = 2,ecolor='k',elinewidth=1,ms=7,capsize=3)
# 设置坐标轴标签文本
name=['Upper ','Middle ','lower ','Total ','上层','中层','下层','总']
Songti = fm.FontProperties(fname='C:\Windows\Fonts\simsun.ttc')
plt.xlabel('Growth stage\n生育阶段', fontproperties=Songti, fontsize=14)
plt.ylabel(name[i]+'light interception\n'+name[i+4]+'光截获', fontproperties=Songti, fontsize=14)
# # 创建字体,设置图例 windows自带字体路径
myfont = fm.FontProperties(fname=r'C:\Windows\Fonts\STKAITI.ttf',
size=10)
plt.legend(prop=myfont, fontsize=18,ncol=2,edgecolor='w')#nco列数
plt.tight_layout() #防止保存时大小不合适
plt.savefig(r'C:\Users\Administrator\Desktop\{}light interception.jpg'.format(name[i]), dpi=1000)
plt.close()