From 2a6f87b7dea1d983b4dd947a5868efdfd9946cb7 Mon Sep 17 00:00:00 2001 From: "j.aschauer" Date: Mon, 4 Dec 2023 16:54:36 +0100 Subject: [PATCH 1/2] change order of cost type columns to match position in chain --- app/ptxboa_functions.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/app/ptxboa_functions.py b/app/ptxboa_functions.py index 0d023c56..9f47055e 100644 --- a/app/ptxboa_functions.py +++ b/app/ptxboa_functions.py @@ -109,7 +109,40 @@ def aggregate_costs( # calculate total costs: res["Total"] = res.sum(axis=1) - return res + return sort_cost_type_columns_by_position_in_chain(res) + + +def sort_cost_type_columns_by_position_in_chain(df): + """Change cost type column order to match the occurrence in a chain. + + This is necessary for the order of the colors in the stacked barplots (GH #150). + + Parameters + ---------- + df : pd.DataFrame + columns need to be in 'cost_type_order' + + Returns + ------- + pd.DataFrame + same data with changed order of columns. + """ + # + cost_type_order = [ + "Electricity generation", + "Heat", + "Water", + "Electrolysis", + "Electricity and H2 storage", + "Carbon", + "Derivate production", + "Transportation (Pipeline)", + "Transportation (Ship)", + "Total", + ] + assert [c in cost_type_order for c in df.columns] + cols = [c for c in cost_type_order if c in df.columns] + return df[cols] def subset_and_pivot_input_data( From 7f64a4d46a13d55d3acfb29247a3bb7a154f6557 Mon Sep 17 00:00:00 2001 From: Markus Haller Date: Tue, 5 Dec 2023 16:56:58 +0100 Subject: [PATCH 2/2] change order of cost components I would prefer a different order for the cost components --- app/ptxboa_functions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/ptxboa_functions.py b/app/ptxboa_functions.py index 9f47055e..9376e1f1 100644 --- a/app/ptxboa_functions.py +++ b/app/ptxboa_functions.py @@ -130,12 +130,12 @@ def sort_cost_type_columns_by_position_in_chain(df): # cost_type_order = [ "Electricity generation", - "Heat", - "Water", "Electrolysis", "Electricity and H2 storage", - "Carbon", "Derivate production", + "Heat", + "Water", + "Carbon", "Transportation (Pipeline)", "Transportation (Ship)", "Total",