From f75cec93d6b795effb3ec3049d4a498c06c2b7a6 Mon Sep 17 00:00:00 2001 From: virio-andreyana <114650479+virio-andreyana@users.noreply.github.com> Date: Wed, 1 Mar 2023 12:29:36 +0100 Subject: [PATCH] lower log level in plot_summary.py and fix warning reduce the level of "Dropping technology energy balance smaller than {snakemake.config['plotting']['energy_threshold']/10} {units}" and "Total energy balance for {v} of {round(df.sum()[0],2)} {units}" from INFO-> DEBUG. Extra warning fix Add `plt.cla()` in the `for k, v in balances.items()` and take out fig, ax = plt.subplots(figsize=(12,8)) from that for loop to fix RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`). --- scripts/plot_summary.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/plot_summary.py b/scripts/plot_summary.py index 2b9e5534..eadf427c 100644 --- a/scripts/plot_summary.py +++ b/scripts/plot_summary.py @@ -244,6 +244,8 @@ def plot_balances(): balances = {i.replace(" ","_"): [i] for i in balances_df.index.levels[0]} balances["energy"] = [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(): @@ -265,12 +267,12 @@ def plot_balances(): else: units = "TWh/a" - logger.info(f"Dropping technology energy balance smaller than {snakemake.config['plotting']['energy_threshold']/10} {units}") + logger.debug(f"Dropping technology energy balance smaller than {snakemake.config['plotting']['energy_threshold']/10} {units}") logger.debug(df.loc[to_drop]) df = df.drop(to_drop) - logger.info(f"Total energy balance for {v} of {round(df.sum()[0],2)} {units}") + logger.debug(f"Total energy balance for {v} of {round(df.sum()[0],2)} {units}") if df.empty: continue @@ -279,8 +281,6 @@ def plot_balances(): new_columns = df.columns.sort_values() - fig, ax = plt.subplots(figsize=(12,8)) - df.loc[new_index,new_columns].T.plot(kind="bar",ax=ax,stacked=True,color=[snakemake.config['plotting']['tech_colors'][i] for i in new_index]) @@ -302,6 +302,8 @@ def plot_balances(): fig.savefig(snakemake.output.balances[:-10] + k + ".pdf", bbox_inches='tight') + + plt.cla() def historical_emissions(cts):