#统一设置图片字体
plt.rc('font',family='Palatino Linotype')#Times New Roman#定义柱状图位置#location 1
n1 =1# This is our first dataset (out of 2)
t =2# Number of datasets
d =6# Number of sets of bars
w =0.8# Width of each bar
store1_x =[t*element +(1-w/2)*n1 for element inrange(d)]#Location 2
n2 =2# This is our second dataset (out of 2)
t =2# Number of datasets
d =6# Number of sets of bars
w =0.8# Width of each bar
store2_x =[t*element +(1+w/2)*n1 for element inrange(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)#XY轴的刻度及标签
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])#去除x轴刻度,Y轴刻度向内
ax.tick_params(axis='x', which='both', length=0,direction='in')#
ax.tick_params(axis='y', which='both', direction='in',width=1)##设置XY轴名称,字体大小,加粗
plt.xlabel('Vegetation indices',size=12,weight ='bold')
plt.ylabel('Values of normalized vegetation indices',size=12,weight ='bold')#去除边框线# ax.spines['top'].set_visible(False)# ax.spines['right'].set_visible(False)#设置边框宽度
ax.spines['bottom'].set_linewidth('1.0')#设置边框线宽为2.0
ax.spines['top'].set_linewidth('1.0')#设置边框线宽为2.0
ax.spines['right'].set_linewidth('1.0')#设置边框线宽为2.0
ax.spines['left'].set_linewidth('1.0')#设置边框线宽为2.0#去除图片周围空白
plt.subplots_adjust(top=0.98, bottom=0.12, right=0.99, left=0.09, hspace=0, wspace=0)# plt.margins(0, 0)
plt.savefig('./VIs_barss.png', dpi=600)
plt.show()