1.绘制不同类别植被指数均值标准差直方图
import pandas as pd
import numpy as np
import csv
from matplotlib import pyplot as plt
1.1从excel种读取数据
JOVIs = pd.read_csv(r'G:\数据恢复\2021工作\0325_野外实验设计\4_第二届数字地球大会\3_实验处理\9_出图V2\2_植被指数\Fieldfeature0416.csv')
1.2数据预处理(不同类别归一化均值标准差)
JOVIs_healthy = JOVIs[JOVIs['levelnew']==0].iloc[:,4:10]
JOVIs_healthy = JOVIs_healthy[['PSRI2','REDSI','DSWI1','NDVI','NDVIre2','TVI']]
JOVIs_healthy_NOR = JOVIs_healthy.apply(lambda x: (x - np.min(x)) / (np.max(x) - np.min(x)))
JOVIs_healthy_mean = JOVIs_healthy_NOR.mean()
JOVIs_healthy_std = JOVIs_healthy_NOR.std()
JOVIs_disease = JOVIs[JOVIs['levelnew']==1].iloc[:,4:10]
JOVIs_disease = JOVIs_disease[['PSRI2','REDSI','DSWI1','NDVI','NDVIre2','TVI']]
JOVIs_disease_NOR = JOVIs_disease.apply(lambda x: (x - np.min(x)) / (np.max(x) - np.min(x)))
JOVIs_disease_mean = JOVIs_disease_NOR.mean()
JOVIs_disease_std = JOVIs_disease_NOR.std()
1.3画图
plt.rc('font',family='Palatino Linotype')
n1 = 1
t = 2
d = 6
w = 0.8
store1_x = [t*element + (1-w/2)*n1 for element in range(d)]
n2 = 2
t = 2
d = 6
w = 0.8
store2_x = [t*element + (1+w/2)*n1 for element in range(d)]
ax=plt.subplot()
plt.bar(store1_x,JOVIs_healthy_mean,yerr=JOVIs_healthy_std/2,capsize=5)
plt.bar(store2_x,JOVIs_disease_mean,yerr=JOVIs_disease_std/2,capsize=5)
plt.legend(['Healthy','Disease'],loc="upper left").get_frame().set_linewidth(0.0)
ax.set_xticks([1,3,5,7,9,11])
VIs_name = ["PSRI", "REDSI", "DSWI", "NDVI", "NDVIre", "TVI"]
ax.set_xticklabels(VIs_name)
ax.set_yticks([0,0.2,0.4,0.6,0.8,1])
ax.tick_params(axis='x', which='both', length=0,direction='in')
ax.tick_params(axis='y', which='both', direction='in',width=1)
plt.xlabel('Vegetation indices',size= 12,weight = 'bold')
plt.ylabel('Values of normalized vegetation indices',size= 12,weight = 'bold')
ax.spines['bottom'].set_linewidth('1.0')
ax.spines['top'].set_linewidth('1.0')
ax.spines['right'].set_linewidth('1.0')
ax.spines['left'].set_linewidth('1.0')
plt.subplots_adjust(top=0.98, bottom=0.12, right=0.99, left=0.09, hspace=0, wspace=0)
plt.savefig('./VIs_barss.png', dpi=600)
plt.show()