import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from scipy.interpolate import griddata
import netCDF4 as nc
from matplotlib.colors import LinearSegmentedColormap
import cmaps
import cartopy.crs as ccrs
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
import sys
sys.path.append('/home/wangnan/data/era5/')
import maps
import matplotlib.colors as colors
import xarray as xr
#read data
df1=pd.read_excel('/home/wangnan/forzy/pmf.xlsx',sheet_name='summer')
df2=pd.read_excel('/home/wangnan/forzy/pmf.xlsx',sheet_name='fall')
#set font
font1={'family' : 'Arial',
'weight' : 'normal',
'size' : 16,
}
#begin to plot
fig=plt.figure(num=1,figsize=(18,25))
ind=np.arange(len(df1['percentage'])) #得到x轴的长度信息
width=0.35
plt.subplot(6,1,1)
plt.bar(ind-width/2,df1['Vehicle emission'], width,facecolor='lightskyblue',edgecolor='k',label='summer')
plt.bar(ind+width/2,df2['Vehicle emission'], width,facecolor='lightskyblue',edgecolor='k',label='fall',hatch=('\\')) #hatch改变柱子的pattern,这个设置很骚
plt.legend(fontsize=16) #修改label的字体
plt.title('Factor 1: Vehicle emission',font1)
plt.ylabel('% of species',font1)
#set labels
plt.tick_params(labelsize=16)
plt.xticks([]) #关掉x轴
plt.subplot(6,1,2)
plt.bar(ind-width/2,df1['LPG usage'], width,facecolor='lightcoral',edgecolor='k',label='summer')
plt.bar(ind+width/2,df2['LPG usage'], width,facecolor='lightcoral',edgecolor='k',label='fall',hatch=('\\'))
plt.title('Factor 2: LPG usage',font1)
plt.ylabel('% of species',font1)
plt.legend(fontsize=16)
plt.tick_params(labelsize=16)
plt.xticks([])
plt.subplot(6,1,3)
plt.bar(ind-width/2,df1['Gasoline evaporation'], width,facecolor='violet',edgecolor='k',label='summer')
plt.bar(ind+width/2,df2['Gasoline evaporation'], width,facecolor='violet',edgecolor='k',label='fall',hatch=('\\'))
plt.title('Factor 3: Gasoline evaporation',font1)
plt.tick_params(labelsize=16)
plt.ylabel('% of species', font1)
plt.legend(fontsize=16)
plt.xticks([])
plt.subplot(6,1,4)
plt.bar(ind-width/2,df1['Paint & varnish'], width,facecolor='grey',edgecolor='k',label='summer')
plt.bar(ind+width/2,df2['Paint & varnish'], width,facecolor='grey',edgecolor='k',label='fall',hatch=('\\'))
plt.title('Factor 4: Paint & varnish',font1)
plt.ylabel('% of species', font1)
plt.legend(fontsize=16)
plt.tick_params(labelsize=16)
plt.xticks([])
plt.subplot(6,1,5)
plt.bar(ind-width/2,df1['Consumer'], width,facecolor='turquoise',edgecolor='k',label='summer')
plt.bar(ind+width/2,df2['Consumer'], width,facecolor='turquoise',edgecolor='k',label='fall',hatch=('\\'))
plt.title('Factor 5: Consumer & household product',font1)
plt.ylabel('% of species', font1)
plt.legend(fontsize=16)
plt.tick_params(labelsize=16)
plt.xticks([])
plt.subplot(6,1,6)
plt.bar(ind-width/2,df1['BVOC'], width,facecolor='lawngreen',edgecolor='k',label='summer')
plt.bar(ind+width/2,df2['BVOC'], width,facecolor='lawngreen',edgecolor='k',label='fall',hatch=('\\'))
plt.title('Factor 6: BVOC',font1)
plt.tick_params(labelsize=16)
plt.ylabel('% of species', font1)
plt.legend(fontsize=16)
plt.xticks(ind,df1['percentage'])
plt.xticks(rotation=60)
#set labels
plt.tick_params(labelsize=16)
plt.savefig('./pmf.png')
plt.show()