python 柱状图

#导入相应包
import pandas as pd 
import matplotlib.pyplot as plt
from pandas import Series,DataFrame
from pylab import mpl
导入数据
df = pd.read_excel('f://Research/2020/Xionjianli/Data/DiversityIdex.xlsx',sheet_name='Sheet6')
#定义字体格式大小
plt.rc('font',family='Times New Roman') 
mpl.rcParams['font.size']=10
#定义画布
plt.figure(figsize=(8,6),dpi=300)
sh=df['shannon_Mean']
si=df['simpson_Mean']
sh_se=df['shannon_SE']
si_se=df['simpson_SE']
绘制柱状图
plt.bar(df.index,df['shannon_Mean'],width=0.3,yerr=sh_se,error_kw={'ecolor':'0.2','capsize':2},label='shannon',color='r')#画纵向柱状图
plt.bar(df.index+0.3,df['simpson_Mean'],width=0.3,yerr=si_se,error_kw={'ecolor':'0.2','capsize':2},label='simpson',color='mediumblue')
plt.xticks(df.index+0.15,df['Unnamed: 0'].values,rotation=20)  #X轴上的刻度名称
plt.tick_params(labelsize=10)#字体大小
plt.legend(loc=5,framealpha=0,bbox_to_anchor=(1.6, 0.5))#显示图的位置

python 柱状图_第1张图片

import pandas as pd 
import matplotlib.pyplot as plt
from pandas import Series,DataFrame
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/DiversityIdex.xlsx',sheet_name='Sheet6')
#读取表格
sh=df['shannon_Mean']
si=df['simpson_Mean']
sh_se=df['shannon_SE']
si_se=df['simpson_SE']
#提取数据
plt.figure(figsize=(8,4),dpi=300)#定义画布
plt.tight_layout()
plt.bar(df.index,df['shannon_Mean'],width=0.45,yerr=sh_se,error_kw={'ecolor':'0.2','capsize':2},label='shannon',color='r',edgecolor='black')#画纵向柱状图
plt.bar(df.index+0.45,df['simpson_Mean'],width=0.45,yerr=si_se,error_kw={'ecolor':'0.2','capsize':2},color='mediumblue',label='simpson')
plt.xticks(df.index+0.225,df['Unnamed: 0'].values,fontsize=16)  #X轴上的刻度名称
# plt.tick_params(labelsize=16)#字体大小
plt.legend(loc=5,framealpha=0,bbox_to_anchor=(1.27, 0.6),fontsize=16)#显示图的位置
plt.savefig('F://Research/2020/Xionjianli/Data/DiversityIdex.png',dpi=300,bbox_inches='tight')
plt.show()  

python 柱状图_第2张图片

import pandas as pd 
import matplotlib.pyplot as plt
from pandas import Series,DataFrame
from pylab import mpl
from matplotlib.pyplot import MultipleLocator
df = pd.read_excel('f://Research/2020/Xionjianli/Data/DiversityIdex.xlsx',sheet_name='Sheet6')

plt.rc('font',family='Times New Roman') 
mpl.rcParams['font.size']=16
ac=df['ace_Mean']
ac_se=df['ace_SE']
chao=df['chao_Mean']
chao_se=df['chao_SE']

plt.figure(figsize=(8,4),dpi=300)
plt.tight_layout()#

plt.bar(df.index,df['ace_Mean'],width=0.45,yerr=ac_se,error_kw={'ecolor':'0.2','capsize':2},label='ace',color='r',edgecolor='black')#画纵向柱状图
plt.bar(df.index+0.45,df['chao_Mean'],width=0.45,yerr=chao_se,error_kw={'ecolor':'0.2','capsize':2},label='chao',color='mediumblue',edgecolor='black')

plt.xticks(df.index+0.225,df['Unnamed: 0'].values) 
plt.legend(loc=5,framealpha=0,bbox_to_anchor=(1.22, 0.6),fontsize=16)

plt.savefig('F://Research/2020/Xionjianli/Data/DiversityIdex(ace).png',dpi=300,bbox_inches='tight')
plt.show()

python 柱状图_第3张图片

你可能感兴趣的:(python)