def plt_station(_df, _df_16, _df_84, ax, st, var, ylim, yscale='linear'): ax.set_xticks(range(1, 12, 2)) _df_s = _df[_df['station'] == st] _df_s16 = _df_16[_df_16['station'] == st] _df_s84 = _df_84[_df_84['station'] == st] x = _df_s['month'] y = _df_s lines = [] labels = [] for source in _df_s['source'].unique(): _df_ss16 = _df_s16[_df_s16['source'] == source].set_index('month').reindex(range(1, 13)) _df_ss84 = _df_s84[_df_s84['source'] == source].set_index('month').reindex(range(1, 13)) ax.fill_between(_df_ss16.index, _df_ss16[var], _df_ss84[var], color=get_case_col(source), alpha=0.3) for source in _df_s['source'].unique(): _df_ss = _df_s[_df_s['source'] == source].set_index('month').reindex(range(1, 13)) # print(_df_ss[var]) line = ax.plot(_df_ss.index, _df_ss[var], color=get_case_col(source), label=source, marker='*', markersize=4) lines = lines + line # s[0] labels.append(get_nice_name_case(source)) ax.set_yscale(yscale) ca = coll_ltr.loc[st, dall_c] ax.set_title(st)#+',' +ca) if ylim is not None: ax.set_ylim(ylim) ax.set_xlim([.8,12.2]) return labels, lines
plt_da.drop(drop_coords).groupby('time.hour').mean().plot(x='hour',yscale='log', ylim=[3,500], label=case_name, norm=mcolors.LogNorm(vmin=10,vmax=8e3), cmap='Reds') # %% from sectional_v2.util.plot.colors import get_case_col#(case) # %% import matplotlib.colors as mcolors st = '2008-03-01' et = '2008-06-01' cmap='viridis' var = 'NCONC01' fig, axs = plt.subplots(1, figsize=[8,5], sharex=True) for i in np.arange(len(stations)): for case_name in cases_sec + cases_orig: col = get_case_col(case_name) ax = axs#[0] plt_ds = dic_sd[case_name] #['dNdlogD_mod']+dic_sd[case_name]['dNdlogD_sec']) plt_ds = plt_ds.sel(time=slice(st,et)).isel(station=i, lev=-1) plt_da = plt_ds[var]# + plt_ds['dNdlogD_sec'] plt_da = plt_da.groupby('time.hour').median()#.median('station') plt_da.plot( yscale='log', c =col, label='_nolegend_', alpha=0.2)#, linewidth=0.2)#x='hour')#, yscale='log', ylim=[3,500], , norm=mcolors.LogNorm(vmin=10,vmax=8e3), cmap=cmap, ax=ax) #ax.set_title(f'{case_name}, {stations[i]}') for case_name in cases_sec + cases_orig: col = get_case_col(case_name) ax = axs#[0] plt_ds = dic_sd[case_name] #['dNdlogD_mod']+dic_sd[case_name]['dNdlogD_sec']) plt_ds = plt_ds.sel(time=slice(st,et)).isel( lev=-1) plt_da = plt_ds[var]# + plt_ds['dNdlogD_sec']
plot_grid(dic_finish, subs='AUT', ylim=[0, 8e3]) # %% from sectional_v2.constants import collocate_locations station = 'ASP' colors_source = get_cmap_dic(dic_finish.keys()) colors_source['EUSAAR'] = 'k' for station in dic_finish[cases[0]].coords['station'].values: fig, axs = plt.subplots(2, 2) seasons = ['SPR', 'SUM', 'AUT', 'WIN'] for seas, ax in zip(seasons, axs.flatten()): for key in dic_finish.keys(): plt_median_perc(dic_clean[key]['dNdlog10dp'], station, key, color=get_case_col(key), ax=ax, subs=seas, percs=[16, 84], yscale='log', ylim=[10, 1e4]) ax.set_title(station + ', ' + seas) plt.legend() plt.show() # %% from sectional_v2.constants import collocate_locations station = 'ASP' colors_source = get_cmap_dic(dic_finish.keys()) colors_source['EUSAAR'] = 'k' for station in dic_finish[cases[0]].coords['station'].values:
def plot_grid(dic_finish, subs='TOT', st_ls=None, name='all_stations', ylim=[5, 8.8e3], yscale='linear', plot_sec=True, nr_col=4, figsize=None, ylim_ZEP=[0, 500]): colors_source = get_cmap_dic(dic_finish.keys()) colors_source['EUSAAR'] = 'k' dic_ds = dic_finish t_cs = dic_ds[list(dic_ds.keys())[0]] st_ls = list(get_ordered_stations()) # st_ls = list(loc_tr[loc_tr['Region']==reg].index) print(list(st_ls)) if len(st_ls) > nr_col: nr_row = int(np.ceil(len(st_ls) / nr_col)) else: nr_row = 1 nr_col = len(st_ls) if figsize is None: figsize = [10 / 4 * nr_col, 10 / 6 * nr_row] fig, axs = plt.subplots(nr_row, nr_col, sharex=True, sharey=True, figsize=figsize) axs_nf = axs if nr_row > 1: axs = axs.flatten() for station, ax in zip(st_ls, axs): lines = [] labels = [] for key in dic_finish.keys(): _ds = dic_finish[key] #if 'dNdlog10dp_sec' in _ds: # plt_perc(dic_finish[key]['dNdlog10dp_sec'], station, key, # color=get_case_col(key), # ax=ax, # subs=subs, percs=[16,84], yscale=yscale, ylim=ylim) ## plt_perc(dic_finish[key]['dNdlog10dp_mod'], station, key, # color=get_case_col(key), # ax=ax, # subs=subs, percs=[16,84], yscale=yscale, ylim=ylim) #else: plt_perc(dic_finish[key]['dNdlog10dp'], station, key, color=get_case_col(key), ax=ax, subs=subs, percs=[16, 84], yscale=yscale, ylim=ylim) for key in dic_finish.keys(): _ds = dic_finish[key] #if 'dNdlog10dp_sec' in _ds: # line =plt_median(dic_finish[key]['dNdlog10dp_sec'], station, key, # color=get_case_col(key), # ax=ax, # subs=subs, percs=[16,84], yscale=yscale, ylim=ylim) # line =plt_median(dic_finish[key]['dNdlog10dp_mod'], station, key, # color=get_case_col(key), # ax=ax, # subs=subs, percs=[16,84], yscale=yscale, ylim=ylim) #else: if 'dNdlog10dp_sec' in _ds: line = plt_median(dic_finish[key]['dNdlog10dp_sec'].where( dic_finish[key]['dNdlog10dp_sec'] > 0), station, key, color=get_case_col(key), ax=ax, subs=subs, percs=[16, 84], yscale=yscale, ylim=ylim, plt_kwargs={'linestyle': 'dashed'}) line = plt_median(dic_finish[key]['dNdlog10dp'], station, key, color=get_case_col(key), ax=ax, subs=subs, percs=[16, 84], yscale=yscale, ylim=ylim) lines = lines + line labels.append(get_nice_name_case(key)) if station == 'ZEP': axins = insert_ZEP(ax) for key in dic_finish.keys(): plt_perc(dic_finish[key]['dNdlog10dp'], station, key, color=get_case_col(key), ax=axins, subs=subs, percs=[16, 84], yscale=yscale, ylim=ylim_ZEP) for key in dic_finish.keys(): plt_median(dic_finish[key]['dNdlog10dp'], station, key, color=get_case_col(key), ax=axins, subs=subs, percs=[16, 84], yscale=yscale, ylim=ylim_ZEP) if 'dNdlog10dp_sec' in _ds: plt_median(dic_finish[key]['dNdlog10dp_sec'], station, key, color=get_case_col(key), ax=axins, subs=subs, percs=[16, 84], yscale=yscale, ylim=ylim_ZEP) ax.indicate_inset_zoom( axins, edgecolor='r', ) fix_ins(axins) if subs == 'TOT': cat = coll_ltr.loc[station, dall_c] ax.set_title(station) #+' '+cat) else: cat = coll_ltr.loc[station, dall_c] ax.set_title(station + ' ' + subs) #+', '+cat) ax.grid(True) ax.spines['left'].set_visible(False) ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) ax.tick_params(axis=u'y', which=u'both', length=0) if nr_row > 1: for ii in range(nr_row): for jj in range(nr_col): if ii != nr_row - 1: axs_nf[ii, jj].set_xlabel('') if jj != 0: axs_nf[ii, jj].set_ylabel('') else: axs_nf[ii, jj].set_ylabel('dN/dlog$_{10}$D [cm$^{-3}$]') fig.tight_layout() lgn = fig.legend( lines, labels, bbox_to_anchor=(0, 1., 1, 0.5), # (0, -0.04, 1., .1), loc='lower center', ncol=4, # mode="expand", borderaxespad=0., fontsize=11, frameon=False) # bbox_to_anchor=(0, 1., 1, 0.5)) #fig.legend(lines, labels, bbox_to_anchor=(0,1.,1,0.5),#(0, -0.04, 1., .1), # loc='lower center', ncol=4, # #mode="expand", # borderaxespad=0., fontsize=11, frameon=False)# bbox_to_anchor=(0, 1., 1, 0.5)) fn = paths_plotsave[ 'eusaar'] + '/sizedist/%s_overview_yscale_%s_sec%s_%s.' % ( name.replace(' ', '-'), yscale, plot_sec, subs) print(fn) make_folders(fn) plt.savefig(fn + 'png', bbox_extra_artists=(lgn, ), bbox_inches='tight') plt.savefig(fn + 'pdf', bbox_extra_artists=(lgn, ), bbox_inches='tight') plt.show()
# %% plot_grid(dic_finish,subs = 'AUT', ylim=[0,8e3]) # %% # %% from sectional_v2.constants import collocate_locations station='ASP' colors_source = get_cmap_dic(dic_finish.keys()) colors_source['EUSAAR']='k' for station in dic_finish[cases[0]].coords['station'].values: fig, axs = plt.subplots(2,2) seasons = ['SPR', 'SUM','AUT','WIN'] for seas, ax in zip(seasons, axs.flatten()): for key in dic_finish.keys(): plt_median_perc(dic_finish[key]['dNdlog10dp'], station, key, color=get_case_col(key), ax=ax, subs=seas, percs=[16,84], yscale='log', ylim=[10,1e4]) ax.set_title(station+', '+ seas) plt.legend() plt.show() # %% from sectional_v2.constants import collocate_locations station='ASP' colors_source = get_cmap_dic(dic_finish.keys()) colors_source['EUSAAR']='k' for station in dic_finish[cases[0]].coords['station'].values: fig, axs = plt.subplots(2,2) seasons = ['SPR', 'SUM','AUT','WIN']