def curve_plot(self, variable, t_max): print("Doing curve plot for variable '{}'.".format(variable)) var = Variable(name=variable) if var.data is None: self.extract_single_dimension(var, t_max=t_max) x = np.arange(t_max) mean = var.data["mean"] std = var.data["std"] plt.plot(x, mean, c='black', lw=2) plt.plot(x, mean + std, c='black', lw=.1) plt.plot(x, mean - std, c='black', lw=.1) plt.fill_between(x, mean + std, mean - std, color='black', alpha=.1) plt.xlabel("t") plt.ylabel(self.format_label(variable)) plt.savefig("{}/curve_plot_{}.pdf".format(self.fig_folder, variable)) if self.display: plt.show() plt.close()
def plot(x, y, y_std, x_label, y_label, fig_title, fig_folder, fig_name, comment=None): plt.figure(figsize=(10, 10)) plt.plot(x, y, c='b', lw=2) plt.plot(x, y + y_std, c='b', lw=.5) plt.plot(x, y - y_std, c='b', lw=.5) plt.fill_between(x, y + y_std, y - y_std, color='b', alpha=.1) plt.xlabel("\n{}".format(x_label), fontsize=12) plt.ylabel("{}\n".format(y_label), fontsize=12) if comment: plt.title("{}\n({})\n".format(fig_title, comment)) else: plt.title("{}\n".format(fig_title)) # if comment: # # plt.text(x=min(x) + (max(x) - min(x)) * 0.5, y=min(y) + (max(y) - min(y)) * 0.5, # s="{}".format(comment)) plt.xlim(min(x), max(x)) plt.ylim(-0.001, 0.1) if not path.exists(fig_folder): mkdir(fig_folder) plt.savefig("{}/{}".format(fig_folder, fig_name)) plt.close()
def analyse_profits(pool_backup, file_name="", folder=None): """ Expected running_mode is 'discrete' :param pool_backup: :param file_name: :param folder: :return: """ if folder is None: folder = "data/figures" os.makedirs(folder, exist_ok=True) def f_cond(xx): if xx < 0.25: return 0 elif xx < 0.5: return 1 elif xx < 0.75: return 2 else: return 3 n_pools = 4 labels = [ "0 <= FoV < 0.25", "0.25 <= FoV < 0.50", "0.50 <= FoV < 0.75", "0.75 <= FoV <= 1" ] parameters = pool_backup.parameters backups = pool_backup.backups assert backups[ 0].running_mode == "discrete", "Expected running_mode is 'discrete'" profit_max = parameters.n_positions * parameters.n_prices * parameters.unit_value x = range(parameters.t_max) for_y = [[[] for j in range(parameters.t_max)] for i in range(n_pools)] for i, b in tqdm.tqdm(enumerate(backups), total=len(backups)): cond = f_cond(b.field_of_view) for t in range(parameters.t_max): for_y[cond][t].append(np.mean(b.profits[t, :]) / profit_max) for i in range(n_pools): y = np.array([np.mean(for_y[i][t]) for t in range(parameters.t_max)]) y_err = np.array( [np.std(for_y[i][t]) for t in range(parameters.t_max)]) plt.plot(x, y, label=labels[i]) plt.fill_between(x, y - (y_err / 2), y + (y_err / 2), color="C{}".format(i), alpha=.25) plt.legend() plt.xlabel("t") plt.ylabel("Mean profit") if file_name: plt.title(file_name) plt.tight_layout() if file_name: plt.savefig("{}/{}_mean_profit_{}_cat.pdf".format( folder, file_name, n_pools)) plt.show()
plt.ylabel('rmse | spread [$m$]') sns.despine() plt.title(f'n_ens:{n_ens}') plt.ylim(ymax=120) plt.savefig( f'{plotdir}/plasimt42_leadtime_vs_skill_and_spread_best_n_ens{n_ens}.svg') # difference mean forecast error and spread vs leadtime plus uncertainty, for fixed n_ens plt.figure(figsize=figsize) plt.plot(sub_df['leadtime'], sub_df['errordiff_svd_rand'], label='rmse svd-rand', color='#1b9e77') plt.fill_between(sub_df['leadtime'], sub_df['errordiff_svd_rand_lower'], sub_df['errordiff_svd_rand_upper'], color='#1b9e77', alpha=0.5) plt.plot(sub_df['leadtime'], sub_df['errordiff_svd_netens'], label='rmse svd-netens', color='#7570b3') plt.fill_between(sub_df['leadtime'], sub_df['errordiff_svd_netens_lower'], sub_df['errordiff_svd_netens_upper'], color='#7570b3', alpha=0.5) plt.plot(sub_df['leadtime'], sub_df['errordiff_rand_netens'], label='rmse rand-netens', color='#d95f02')
mean_percentage_Rco = np.nanmean(percentage_Rco, axis=0) mean_percentage_Raslip = np.nanmean(percentage_Raslip, axis=0) total_percentage = mean_percentage_Easlip + mean_percentage_Rco +mean_percentage_Raslip ################################ ts = [] for t1, t2 in zip(epochs[0:-1],epochs[1:]): ts += [t1,t2] ys1 = [] for yi in mean_percentage_Easlip: ys1 += [yi,yi] plt.fill_between(ts, ys1, np.zeros_like(ys1), color='blue') ys2 = [] for yi in mean_percentage_Rco: ys2 += [1-yi, 1-yi] plt.fill_between(ts, ys2, np.ones_like(ys2), color='green') obj = plt.fill_between(ts, ys1, ys2, color='red') plt.grid('off') label_patch1 = mpatches.Patch(color='green') label_patch2 = mpatches.Patch(color='red') label_patch3 = mpatches.Patch(color='blue') plt.legend([label_patch1, label_patch2, label_patch3], [r'$R^{\bf{co}}$', r'$R^{\bf{aslip}}$',r'$E^{\bf{aslip}}$'],
def plot_slip_overview(slip, output_file, if_x_log=False, xlim=[0, 1344], ylim = [0,100], yticks = [20, 40, 60], xticks = [1, 10, 100, 1000], xticklabels = [r'$10^0$', r'$10^1$', r'$10^2$', r'$10^3$'], rotation = 45, fontsize = 10, ): num_subflts_strike = slip.num_subflt_along_strike num_subflts_dip = slip.num_subflt_along_dip epochs = slip.get_epochs() fig, axes = plt.subplots(num_subflts_dip, num_subflts_strike, sharex=True, sharey=True) for ii in range(num_subflts_dip): for jj in range(num_subflts_strike): ax = axes[ii][jj] slip_subflt = slip.get_cumu_slip_at_subfault(ii,jj) plt.sca(ax) plt.fill_between(x=epochs, y1=slip_subflt, y2=0, color='r') if if_x_log: ax.set_xscale('log') plt.xlim(xlim) plt.ylim(ylim) plt.grid('on') plt.box('on') plt.tick_params(axis='both',which='both', bottom='off', top='off', left='off', right='off', labelbottom='off', labeltop='off', labelleft='off', labelright='off') fig.subplots_adjust(hspace=0, wspace=0) for ax in axes[-1,::2]: plt.sca(ax) plt.tick_params(axis='x',which='major', bottom='on', top='off', left='off', right='off', labelbottom='on', labeltop='off', labelleft='off', labelright='off') ax.set_xticks(xticks) ax.set_xticklabels(xticklabels, rotation=rotation, fontsize=fontsize) plt.xlabel('day') for ax in axes[0,1::2]: plt.sca(ax) plt.tick_params(axis='x',which='major', bottom='off', top='on', left='off', right='off', labelbottom='off', labeltop='on', labelleft='off', labelright='off') ax.set_xticks(xticks) ax.set_xticklabels(xticklabels, rotation=rotation, fontsize=fontsize) plt.xlabel('day') for ax in axes[::2,0]: plt.sca(ax) plt.tick_params(axis='y',which='major', bottom='off', top='off', left='on', right='off', labelbottom='off', labeltop='off', labelleft='on', labelright='off') ax.set_yticks(yticks) #ax.set_yticklabels(range(0,100,20)) for tick in ax.yaxis.get_major_ticks(): tick.label.set_fontsize(10) tick.label.set_rotation('horizontal') plt.ylabel('slip/m') for ax in axes[::2,-1]: plt.sca(ax) plt.tick_params(axis='y',which='major', bottom='off', top='off', left='off', right='on', labelbottom='off', labeltop='off', labelleft='off', labelright='on') ax.set_yticks(yticks) #ax.set_yticklabels(range(0,100,20)) for tick in ax.yaxis.get_major_ticks(): tick.label.set_fontsize(10) tick.label.set_rotation('horizontal') plt.ylabel('slip/m') ax.yaxis.set_label_position("right") fig.set_size_inches(33,10) plt.savefig(output_file) plt.close()