python横向多组柱状图

#导入包
import pandas as pd 
import matplotlib.pyplot as plt
from pandas import Series,DataFrame
import numpy as np
from pylab import mpl
#定义图像字体和字体大小
plt.rc('font',family='Times New Roman') 
mpl.rcParams['font.size']=16
#读取文件
df = pd.read_excel('F://Research/2020/Xionjianli/Data/季节差异显著_phylum1.xls',sheet_name='Sheet1')
#pow(15,1/2)既 15 的 1/2次方
ck=df['Withering_Sd']/pow(15,1/2)
cq=df['Grassy_Sd']/pow(15,1/2)
#绘图大小和清晰度
plt.figure(figsize=(8,10),dpi=300)
#横向柱状图
plt.barh(df.index,df['Withering_Mean'],height=0.3,xerr=ck,error_kw = {'ecolor' : '0.2', 'capsize' :2},label='Withering')
plt.barh(df.index+0.3,df['Grassy_Mean'],height=0.3,xerr=cq,error_kw = {'ecolor' : '0.2', 'capsize' :2},label='Grassy')
#绘制y轴坐标刻度名
plt.yticks(df.index+0.15,df['Species name'].values)  
plt.tick_params(labelsize=16)
# plt.legend(loc=1,framealpha=0)
#绘制图例
plt.legend(loc=5,framealpha=0,bbox_to_anchor=(1.2, 0.5))
plt.axis('tight')
#保存图片
# plt.savefig('F://Research/2020/Xionjianli/Data/季节差异Phylum1(dpi=300).png',dpi=300,bbox_inches='tight')
plt.show()    

python横向多组柱状图_第1张图片

你可能感兴趣的:(python)