python横向柱状图

import pandas as pd 
import matplotlib.pyplot as plt
from pandas import Series,DataFrame
import numpy as np
from pylab import mpl
# df = pd.read_excel('f://Research/2020/Xionjianli/Data/季节差异显著_genus1.xls',sheet_name)

#修改字体大小及其格式
plt.rc('font',family='Times New Roman') 
mpl.rcParams['font.size']=16
#读取EXCEL表格
df = pd.read_excel('F://Research/2020/Xionjianli/Data/季节差异显著_genus1.xls',sheet_name='Sheet2')
#提取数据
ck=df['CKJWD-Sd(%)']/pow(15,1/2)#计算标准误
cq=df['CQKWD-Sd(%)']/pow(15,1/2)
#画图
plt.figure(figsize=(8,4),dpi=300)#定义画布
plt.barh(df.index+0.4,df['Withering'],height=0.4,xerr=ck,error_kw = {
     'ecolor' : '0.2', 'capsize' :2},label='Withering',color='r',edgecolor='black')#画横向柱状图
plt.barh(df.index,df['Grassy'],height=0.4,xerr=cq,error_kw = {
     'ecolor' : '0.2', 'capsize' :2},label='Grassy',color='mediumblue',edgecolor='black')
plt.yticks(df.index+0.2,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, 0.1),fontsize=16)
plt.savefig('F://Research/2020/Xionjianli/Data/季节差异_genus1(dpi=300).png',dpi=300,bbox_inches='tight')
plt.show()    

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

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

ck=df['Withering_Sd']/pow(15,1/2)
cq=df['Grassy_Sd']/pow(15,1/2)
plt.figure(figsize=(8,4),dpi=300)
plt.barh(df.index+0.4,df['Withering_Mean'],height=0.4,xerr=ck,error_kw = {
     'ecolor' : '0.2', 'capsize' :2},label='Withering',color='r',edgecolor='black')
plt.barh(df.index,df['Grassy_Mean'],height=0.4,xerr=cq,error_kw = {
     'ecolor' : '0.2', 'capsize' :2},label='Grassy',color='mediumblue',edgecolor='black')
plt.yticks(df.index+0.2,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, 0.1),fontsize=16)
plt.axis('tight')
plt.savefig('F://Research/2020/Xionjianli/Data/季节差异Phylum1(dpi=300).png',dpi=300,bbox_inches='tight')
plt.show()    

python横向柱状图_第2张图片

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
#读取EXCEL表格
df = pd.read_excel('F://Research/2020/Xionjianli/Data/区域差异显著_phylum1.xls',sheet_name='Sheet1')


# #修改字体大小及其格式
# plt.rc('font',family='Times New Roman') 
# mpl.rcParams['font.size']=16
# #读取EXCEL表格
# # df = pd.read_excel('F://Research/2020/Xionjianli/Data/季节差异显著_genus1.xls',sheet_name='Sheet1')
#提取数据
ck=df['Withering_Sd']/pow(15,1/2)#计算标准误
cq=df['Grassy_Sd']/pow(15,1/2)
#画图
plt.figure(figsize=(8,4),dpi=300)#定义画布
plt.barh(df.index+0.4,df['Withering_Mean'],height=0.4,xerr=ck,error_kw = {
     'ecolor' : '0.2', 'capsize' :2},label='Withering',color='r',edgecolor='black')#画横向柱状图
plt.barh(df.index,df['Grassy_Mean'],height=0.4,xerr=cq,error_kw = {
     'ecolor' : '0.2', 'capsize' :2},label='Grassy',color='mediumblue',edgecolor='black')
plt.yticks(df.index+0.2,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, 0.1),fontsize=16)
plt.savefig('F://Research/2020/Xionjianli/Data/区域差异phylum1(dpi=300).png',dpi=300,bbox_inches='tight')
plt.show()    
# plt.set_tight_layout(True)

python横向柱状图_第3张图片

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
#读取EXCEL表格
df = pd.read_excel('F://Research/2020/Xionjianli/Data/区域差异显著_genus1.xls',sheet_name='Sheet1')


# #修改字体大小及其格式
# plt.rc('font',family='Times New Roman') 
# mpl.rcParams['font.size']=16
# #读取EXCEL表格
# # df = pd.read_excel('F://Research/2020/Xionjianli/Data/季节差异显著_genus1.xls',sheet_name='Sheet1')
#提取数据
ck=df['Withering_Sd']/pow(15,1/2)#计算标准误
cq=df['Grassy_Sd']/pow(15,1/2)
#画图
plt.figure(figsize=(8,4),dpi=300)#定义画布
plt.barh(df.index+0.4,df['Withering_Mean'],height=0.4,xerr=ck,error_kw = {
     'ecolor' : '0.2', 'capsize' :2},label='Withering',color='r',edgecolor='black')#画横向柱状图
plt.barh(df.index,df['Grassy_Mean'],height=0.4,xerr=cq,error_kw = {
     'ecolor' : '0.2', 'capsize' :2},label='Grassy',color='mediumblue',edgecolor='black')
plt.yticks(df.index+0.2,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, 0.1),fontsize=16)
plt.savefig('F://Research/2020/Xionjianli/Data/区域差异genues(dpi=300).png',dpi=300,bbox_inches='tight')
plt.show()    
# plt.set_tight_layout(True)

python横向柱状图_第4张图片

你可能感兴趣的:(python)