import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.cm as cm
import os
import math
import glob
import datetime
import windrose
from windrose import WindroseAxes
from matplotlib import pyplot as plt
from datetime import timedelta
path1=r'C:\1214_BC.csv'
BC=pd.read_csv(path1,header=0,index_col=0)
path2=r'C:\WIND_1214_nR.csv'
wind=pd.read_csv(path2,header=0,index_col=0)
NW=432005
NB=432001
Timeindex=pd.date_range(start='2019-12-14 00:00:00',end='2019-12-15 01:00:00',freq='0.2S')
time_list=pd.date_range(start='2019-12-14 00:00:00',end='2019-12-15 00:00:00',freq='0.5H')
BC.index=Timeindex[:NB]
wind.index=Timeindex[:NW]
MeanB=BC.resample('0.5H').mean()
MeanW=wind.resample('0.5H').mean()
StdB=BC.resample('0.5H').std() ##4
Stdw=wind.resample('0.5H').std() ##4
label=['U','V','W']
for ith, star_t in enumerate(time_list[:30]):
end_t = star_t + timedelta(minutes=30) - timedelta(seconds=0.2)
print(ith,star_t, end_t)
sub_BC = BC[star_t:end_t].copy()
sub_w = wind[star_t:end_t].copy()
x= wind[star_t:end_t].index
fig,axs= plt.subplots(nrows=4, ncols=1,figsize=(16,8),sharex=True)
for i in range(4):
if i==3:
M=MeanB.iloc[ith,0]
Su=3.25*StdB.iloc[ith,0]+M
Sd=-3.25*StdB.iloc[ith,0]+M
print(M)
axs[i].plot(x,sub_BC.iloc[:,0],c='b',lw=0.5)
axs[i].axhline(y=M,c='k',lw=0.5)
axs[i].axhline(y=Su,c='r',lw=0.5,linestyle='dashed')
axs[i].axhline(y=Sd,c='r',lw=0.5,linestyle='dashed')
axs[i].set_ylabel('BC(μg m$^-$$^3$)')
else:
M=MeanW.iloc[ith,i]
Su=3.25*Stdw.iloc[ith,i]+M
Sd=-3.25*Stdw.iloc[ith,i]+M
axs[i].plot(x,sub_w.iloc[:,i],c='b',lw=0.5)
axs[i].axhline(y=M,c='k',lw=0.5)
axs[i].axhline(y=Su,c='r',lw=0.5,linestyle='dashed')
axs[i].axhline(y=Sd,c='r',lw=0.5,linestyle='dashed')
axs[i].set_xlim(star_t,end_t)
axs[i].set_ylabel(label[i]+'(ms$^-$$^1$)')
for spine in ["top",'right']:
axs[0].spines[spine].set_visible(False)
axs[1].spines[spine].set_visible(False)
axs[2].spines[spine].set_visible(False)
axs[3].spines['top'].set_color('None')
axs[3].spines['right'].set_color('None')
plt.savefig(str(ith)+'.png',dpi=300,bbox_inches = 'tight')
网友评论