def plot_cumsum_plot(baseline, scenario1, scenario2, scenario3): journal = Journal.POWERPOINT_A3 fig, ax = init_figure(nrows=1, ncols=1, columnes=Columnes.ONE, journal=journal) lbase = plot_cumsum_by_scenario(baseline[baseline.is_home], ax, label='Baseline') l1 = plot_cumsum_by_scenario(scenario1[scenario1.is_home], ax, label='Scenario 1') l2 = plot_cumsum_by_scenario(scenario2, ax, label='Scenario 2') l3 = plot_cumsum_by_scenario(scenario3, ax, label='Scenario 3') xlim = plt.xlim() lxy = plt.plot(np.arange(0, xlim[1]), np.arange(0, xlim[1]), label='x=y (only using pv generation)', color='k', linestyle=':', linewidth=2) lyx = plt.plot(np.arange(0, xlim[1]), - np.arange(0, xlim[1]), label='x=-y (only using grid generation)', color='k', linestyle=':', linewidth=2) lyx = plt.plot(np.arange(0, xlim[1]), 0 * np.arange(0, xlim[1]), label=None, color='k', linestyle='--', linewidth=2) xlim = plt.xlim() ylim = plt.ylim() ylim = (ylim[0], xlim[1]) print(ylim) ax.set_ylim(ylim) ax.set_xlim((0, xlim[1])) plt.xlabel('Total energy used by cars (cumulative) [MWh]', labelpad=15) plt.ylabel('PV charging - grid charging \n (cumulative) [MWh]', labelpad=15) leg = plt.legend(ncol=3, loc='upper left', bbox_to_anchor=(-0.15, -0.2), borderpad=0., frameon=False) plt.tight_layout() bbox_extra_artists = [fig, leg, ax] save_figure(os.path.join('plots', 'cumulative_energy_plot', 'cumsum_all_scenarios.png'), bbox_extra_artists=bbox_extra_artists)
# handle._linewidth = 50 leg = ax.legend(handles=handles, labels=labels, loc='upper left', frameon=False, bbox_to_anchor=(-0.14, -0.15), ncol=4) plt.xlabel("Time of tracking aggregated by week", labelpad=15) plt.ylabel( r"Emissions per Person in $\frac{\text{kg CO2 equivalent}}{\text{week}}$", labelpad=20) bbox_extra_artists = [fig, leg] save_figure(fig_out, bbox_extra_artists=bbox_extra_artists) plt.close(fig) # calculate average Co2 savings per user df_avco2 = df_all.groupby('scenario')['co2'].mean() df_avco2 = df_avco2.Baseline - df_avco2 print(plot_name) print("Average savings per scenario relative to the baseline:") print(df_avco2) print(10 * "%") # data_list = [df_b, df_s1, df_s2, df_s3] # journal = Journal.POWERPOINT_A3 # fig, axs = init_figure(nrows=2,
df_kwp = get_kwp(df_kwp) journal = Journal.POWERPOINT_A3 fig, axes = init_figure(nrows=1, ncols=2, columnes=Columnes.ONE, fig_height_mm=120, journal=journal, sharex=False, sharey=False, gridspec_kw={'width_ratios': [2, 1]}) plt.sca(axes[0]) ax = axes[0] sns.lineplot(data=daily_pv_per_user, x="start", y="generated_by_pv", linewidth=1.5, ax=ax) ax.set_xlabel('Days in 2017 [d]') ax.set_ylabel('Daily PV generation [kWh]') t_start = project_constants['t_start'] t_end = project_constants['t_end'] x_dates = pd.date_range(start=t_start, end=t_end, freq='M', ) + datetime.timedelta(days=1) axes[0].set_xticks(x_dates[::2]) axes[0].xaxis.set_major_formatter(mdates.DateFormatter('%b')) plt.sca(axes[1]) sns.histplot(data=df_kwp, x='max_kW', ax=axes[1], bins=np.arange(0, 40, 5)) plt.xlabel('kWp [kW]') plt.ylabel('User count') axes[1].set_xticks([0, 10, 20, 30], minor=False) plt.xlim((0, 35)) save_figure(fig_out)
journal=journal, sharex=True, sharey=True) for ix, column_name in enumerate(column_names): ax = axs[ix // 2, ix % 2] plot_hist(df, column_name, ax=ax) ax.set_title(titles[ix] + f" - mean: {df[column_name].mean():.0f} \%") # ax.grid(which='both') ax.set_xlabel(None) ax.set_ylabel(None) ax.grid(b=True, which='both') ax.set_xlim(0, 100) ax.set_ylim(0, 60) ax.set_yticks([10, 20, 30, 40, 50, 60], minor=True) # labels # https://stackoverflow.com/questions/16150819/common-xlabel-ylabel-for-matplotlib-subplots fig.add_subplot(111, frameon=False) plt.tick_params(labelcolor='none', top=False, bottom=False, left=False, right=False) plt.xlabel("Home charging energy demand covered by PV [\%]", labelpad=15) plt.ylabel("User count", labelpad=15) plt.grid(b=False, which='both') save_figure(output_path)
label='Scenario 1') ax0.scatter(df['total_demand_s2'], df['scenario2'], s=size, label='Scenario 2') ax0.scatter(df['total_demand_s3'], df['scenario3'], s=size, label='Scenario 3') ax0.set_xlabel("Total demand [kWh]") ax0.set_ylabel("Coverage by PV [\%]") ax1.scatter(df['max_kW'], df['baseline'], s=size) ax1.scatter(df['max_kW'], df['scenario1'], s=size) ax1.scatter(df['max_kW'], df['scenario2'], s=size) ax1.scatter(df['max_kW'], df['scenario3'], s=size) ax1.set_xlabel("Peak power [kW]") ax1.set_xlim(0, 30) # ax1.ylabel("coverage by PV [\%]") leg = ax0.legend(loc='upper left', frameon=False, bbox_to_anchor=(-0.35, -0.15), ncol=4, markerscale=3) bbox_extra_artists = [fig, leg] fig_out = os.path.join('plots', 'sensitivity_kwp_bevdemand', 'sensitivity_kwp_bevdemand.png') save_figure(fig_out, bbox_extra_artists=bbox_extra_artists, dpi=10)
# gridspec_kw={"height_ratios":[1, 0.05]}) ) plt.sca(ax) # sns.heatmap(matrix, ax=ax) im = ax.imshow(matrix, aspect='auto', cmap='viridis', interpolation='None') # PCM=ax.get_children()[-2] #get the mappable, the 1st and the 2nd are the x and y axes # plt.colorbar(PCM, ax=ax) # plt.colorbar() plt.grid(b=None) plt.xlabel("Days in study") plt.ylabel("Hours of the day") plt.yticks([0, 6, 12, 18, 24]) # fig.colorbar(im, cax=cax, orientation="horizontal") im.set_clim([0, 1]) # cb = fig.colorbar(im, orientation="horizontal", pad=0.5, shrink=0.5) divider = make_axes_locatable(ax) cax = divider.new_vertical(size="5%", pad=1.0, pack_start=True) fig.add_axes(cax) cb = fig.colorbar(im, cax=cax, orientation="horizontal", fraction=0.5) cb.outline.set_visible(False) cb.set_label("Percentage of cars at home") # cb.set_ticks(np.arange(0, 1.2, 0.2)) # cb.ax.set_xticklabels(np.arange(0, 1.2, 0.2)) # plt.savefig(fig_out[:-3] + "pdf") # plt.close() save_figure(fig_out, dpi=10)
if plt_scatter: leg = plt.figlegend(handles=handles, labels=labels, loc='upper left', ncol=2, frameon=False, bbox_to_anchor=(0.15, 0), labelspacing=0.1, columnspacing=0.1) leg.legendHandles[1].set_alpha(1) # no alpha for scatter circle leg.legendHandles[1].set_sizes([200]) else: leg = plt.figlegend(handles=handles, labels=labels, loc='upper left', ncol=3, frameon=False, bbox_to_anchor=(0.03, 0), labelspacing=0.1, columnspacing=1) bbox_extra_artists = [fig, leg] # save save_figure(os.path.join('plots', 'quantile_plots', 'plot_quantile_coverage_year.png'), bbox_extra_artists=bbox_extra_artists) plt.close(fig)
ax.xaxis.set_major_locator(mdates.HourLocator(byhour=11)) ax.xaxis.set_major_formatter(mdates.DateFormatter('%a')) plt.sca(ax) # x axis date formating ax.xaxis.set_minor_locator(mdates.HourLocator(byhour=[0, 12])) ax.xaxis.set_minor_formatter(mdates.DateFormatter('%H:%M')) ax.tick_params(axis='x', which='minor', pad=10) ax.tick_params(axis='x', which='major', pad=40) ax.tick_params(axis='x', which='major', bottom=True) ax.tick_params(axis='x', which='minor', bottom=True) plt.xticks(rotation=0, horizontalalignment="center") ax.tick_params(axis='x', which='major', length=0) for tick in ax.xaxis.get_minor_ticks(): tick.label.set_fontsize(14) ax.xaxis.grid(True) ax.yaxis.grid(True) ax.set_ylim((0, 101)) ax2.set_ylim((0, 10.1)) frame = lgd.get_frame() frame.set_facecolor('#ebefe8') ax.spines['top'].set_visible(False) save_figure(figure_out, bbox_extra_artists=[lgd], dpi=5)
linewidth=3, label=r"${} * \Delta_{{SoC}} + {} * ".format( round(params_sqrt['dsoc'], 3), round( params_sqrt['np.sqrt(dsoc)'], 3)) + \ r"\sqrt{{ \Delta_{{SoC}} }}$, $R^2 = {}$".format( round(r2_sqrt, 2)) ) # ln_lin, = ax.plot( x, y_lin, linestyle=':', color='orange', linewidth=3, label='linear fit', zorder=10 # draw this line on top ) leg = ax.legend(handles=[ln_sqrt, ln_lin], loc=2, frameon=False) leg.set_zorder(20) frame = leg.get_frame() frame.set_facecolor('#ebefe8') # frame.set_edgecolor('#ebefe8') ax.text(0.99, 0.01, r"N = \num{{ {} }}".format(df.shape[0]), \ horizontalalignment='right', verticalalignment='bottom', \ transform=ax.transAxes) save_figure(os.path.join(".", "plots", "power_factor", "power_factor.png"))