fix plot bugs

This commit is contained in:
lisazeyen 2023-04-05 15:45:07 +02:00
parent 461ea66185
commit f2ff8beae8

View File

@ -41,6 +41,8 @@ def rename_techs(label):
"ground heat pump", "ground heat pump",
"resistive heater", "resistive heater",
"Fischer-Tropsch", "Fischer-Tropsch",
"land transport fuel cell",
"land transport oil"
] ]
rename_if_contains_dict = { rename_if_contains_dict = {
@ -268,7 +270,6 @@ def plot_balances():
i for i in balances_df.index.levels[0] if i not in co2_carriers i for i in balances_df.index.levels[0] if i not in co2_carriers
] ]
fig, ax = plt.subplots(figsize=(12, 8))
for k, v in balances.items(): for k, v in balances.items():
df = balances_df.loc[v] df = balances_df.loc[v]
@ -280,7 +281,7 @@ def plot_balances():
# remove trailing link ports # remove trailing link ports
df.index = [ df.index = [
i[:-1] i[:-1]
if ((i not in ["co2", "NH3"]) and (i[-1:] in ["0", "1", "2", "3"])) if ((i not in ["co2", "NH3", "H2"]) and (i[-1:] in ["0", "1", "2", "3"]))
else i else i
for i in df.index for i in df.index
] ]
@ -314,6 +315,8 @@ def plot_balances():
new_columns = df.columns.sort_values() new_columns = df.columns.sort_values()
fig, ax = plt.subplots(figsize=(12, 8))
df.loc[new_index, new_columns].T.plot( df.loc[new_index, new_columns].T.plot(
kind="bar", kind="bar",
ax=ax, ax=ax,
@ -437,7 +440,7 @@ def historical_emissions(countries):
return emissions return emissions
def plot_carbon_budget_distribution(input_eurostat): def plot_carbon_budget_distribution(input_eurostat, input_eea):
""" """
Plot historical carbon emissions in the EU and decarbonization path. Plot historical carbon emissions in the EU and decarbonization path.
""" """
@ -452,6 +455,20 @@ def plot_carbon_budget_distribution(input_eurostat):
plt.rcParams["xtick.labelsize"] = 20 plt.rcParams["xtick.labelsize"] = 20
plt.rcParams["ytick.labelsize"] = 20 plt.rcParams["ytick.labelsize"] = 20
path_cb = "results/" + snakemake.params.RDIR + "csvs/"
countries = snakemake.config["countries"]
emissions_scope = snakemake.config["energy"]["emissions"]
# this only affects the estimation of CO2 emissions for BA, RS, AL, ME, MK
report_year = snakemake.config["energy"]["eurostat_report_year"]
e_1990 = co2_emissions_year(
countries, input_eurostat, input_eea, opts, emissions_scope,
report_year, year=1990
)
CO2_CAP = pd.read_csv(path_cb + "carbon_budget_distribution.csv", index_col=0)
plt.figure(figsize=(10, 7)) plt.figure(figsize=(10, 7))
gs1 = gridspec.GridSpec(1, 1) gs1 = gridspec.GridSpec(1, 1)
ax1 = plt.subplot(gs1[0, 0]) ax1 = plt.subplot(gs1[0, 0])
@ -459,10 +476,6 @@ def plot_carbon_budget_distribution(input_eurostat):
ax1.set_ylim([0, 5]) ax1.set_ylim([0, 5])
ax1.set_xlim([1990, snakemake.config["scenario"]["planning_horizons"][-1] + 1]) ax1.set_xlim([1990, snakemake.config["scenario"]["planning_horizons"][-1] + 1])
path_cb = "results/" + snakemake.params.RDIR + "/csvs/"
countries = snakemake.config["countries"]
e_1990 = co2_emissions_year(countries, input_eurostat, opts, year=1990)
CO2_CAP = pd.read_csv(path_cb + "carbon_budget_distribution.csv", index_col=0)
ax1.plot(e_1990 * CO2_CAP[o], linewidth=3, color="dodgerblue", label=None) ax1.plot(e_1990 * CO2_CAP[o], linewidth=3, color="dodgerblue", label=None)
@ -540,7 +553,7 @@ def plot_carbon_budget_distribution(input_eurostat):
path_cb_plot = "results/" + snakemake.params.RDIR + "/graphs/" path_cb_plot = "results/" + snakemake.params.RDIR + "/graphs/"
plt.savefig(path_cb_plot + "carbon_budget_plot.pdf", dpi=300) plt.savefig(path_cb_plot + "carbon_budget_plot.pdf", dpi=300)
#%%
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
from _helpers import mock_snakemake from _helpers import mock_snakemake
@ -561,4 +574,5 @@ if __name__ == "__main__":
opts = sector_opts.split("-") opts = sector_opts.split("-")
for o in opts: for o in opts:
if "cb" in o: if "cb" in o:
plot_carbon_budget_distribution(snakemake.input.eurostat) plot_carbon_budget_distribution(snakemake.input.eurostat,
snakemake.input.co2)