import sys, datetime, copy, os from dateutil.relativedelta import relativedelta import numpy as np; np.set_printoptions(threshold=sys.maxsize) import matplotlib; matplotlib.use('Agg') import matplotlib.pyplot as plt import matplotlib.colors as clr from mpl_toolkits.basemap import Basemap import seaborn as sns from matplotlib.colors import ListedColormap from netCDF4 import Dataset #nc = Dataset('Out/FD_Char_1961-2020_1yrs_Daily_Reg_New.nc','r') #../NC/FD_Char_1961-2020_1yrs_Daily_Reg.nc','r') nc = Dataset('Out/R_T2m_Tx_Tm_7Stn_1961-2020.nc','r') year = nc.variables['year'][:] reg = nc.variables['reg'][:] mon = nc.variables['mon'][:] fd = nc.variables['t2m'][:] ; varnm = "T2m" #fd = nc.variables['pr'][:] ; varnm = "R" #regs = ['R1','R2','R3','R4','R5','R6','R7'] var = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"] regs = ['B1','B2','B3','B4','N1','N2','N3'] Max_All = [35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35] aa = fd[:,:,:] aax = round(np.nanmax(aa)); aam = round(np.nanmin(aa)) for i in range(len(mon)): fig, ax = plt.subplots(7,figsize=(6,12)) plt.subplots_adjust(hspace=0.5) a = fd[:,i,:] amax = round(np.nanmax(a)); amin = round(np.nanmin(a)) # amax = Max_All[i]; amin = 15 # amax = aax; amin = aam + 3 print (amax, amin) atext = amax * 4/5 yticks = np.linspace(amin,amax,3) for k in range(len(reg)): x = year[:] # day[0:30] y = fd[:,i,k] # sw1[0:30,k] fit = np.polyfit(x, y, 1) ax[k].scatter(x, y, s=20,c="blue",marker ="^") ax[k].set_ylim(amin,amax) ax[k].set_xlim(0,60) ax[k].plot(x, fit[0]*x + fit[1], 'r-') # ax[k].text(5, atext, 'y='+str(round(fit[0],2))+'*x + '+str(round(fit[1],2))) # ax[k].text(3, atext, 'y='+str(round(fit[0],2))+'*x + '+str(round(fit[1],2))) # ax[k].text(20, atext, 'y='+str(round(fit[0],2))+'*x + '+str(round(fit[1],2)),horizontalalignment='right', verticalalignment='top') # ax[k].text('y='+str(round(fit[0],2))+'*x + '+str(round(fit[1],2)),horizontalalignment='right', verticalalignment='top') # ax[k].set_title(regs[k]) equa=regs[k]+': y='+str(round(fit[0],3))+'*x + '+str(round(fit[1],2)) # ax[k].set_title(regs[k],str(equa)) ax[k].set_title(equa) ax[k].set_yticks(yticks) # fig.suptitle("ABCDF") fig.savefig("Out/Trend_"+varnm+"_"+var[i]+".pdf", bbox_inches="tight", pad_inches=.05, dpi=600) plt.cla() plt.clf() plt.close()