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))#显示图的位置

在这里插入图片描述

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()  

在这里插入图片描述

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()

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值