mescal.plot
Classes
Class to plot LCA indicators and ESM results. |
Functions
|
Generate heatmap visualizations for contribution analysis |
Module Contents
- class mescal.plot.Plot(df_impact_scores: pandas.DataFrame, esm_results_tech: pandas.DataFrame = None, esm_results_res: pandas.DataFrame = None, lifetime: pandas.DataFrame = None)[source]
Class to plot LCA indicators and ESM results.
Initialize the Plot class.
- Parameters:
df_impact_scores (pandas.DataFrame) – dataframe of LCA indicators obtained with the compute_impact_scores method of the ESM class.
esm_results_tech (pandas.DataFrame) – dataframe of ESM results for technologies. It should have the following columns: ‘Run’ (iteration number), ‘Name’ (technology name), ‘Capacity’ (installed capacity of the technology), ‘Production’ (annual production of the technology).
esm_results_res (pandas.DataFrame) – dataframe of ESM results for resources. It should have the following columns: ‘Run’ (iteration number), ‘Name’ (resource name), ‘Import’ (annual import of the resource).
lifetime (pandas.DataFrame) – dataframe of lifetime of technologies.
- plot_indicators_of_resources_for_one_impact_category(resources_list: list[str], impact_category: tuple, metadata: dict = None, filename: str = None, saving_format: str = 'png', saving_path: str = None, show_plot: bool = True, contributions_total_score: bool = False) None[source]
Plot operation LCA indicators for a set of resources for a given impact category.
- Parameters:
resources_list (list[str]) – list of technologies to plot. They should have the same operation/infrastructure units to have a meaningful comparison
impact_category (tuple) – impact category to plot (brightway format)
metadata (dict) – dictionary with metadata to include in the plot. It can include ‘resources_type’, ‘unit’, ‘impact_category_unit’.
filename (str) – name of the file to save the plot. If None, the plot is not saved.
saving_format (str) – format to save the plot, can be ‘png’, ‘jpeg’, ‘pdf’, ‘html’, etc. Default is ‘png’.
saving_path (str) – path to save the plot under the form ‘path/to/folder/’. If None, the plot is saved in the current directory.
show_plot (bool) – if True, the plot is shown in the notebook.
contributions_total_score (bool) – if True, the contributions of all categories to the total score are shown.
- Returns:
None (plot is shown and/or saved)
- Return type:
None
- plot_indicators_of_resources_for_several_impact_categories(resources_list: list[str], impact_categories_list: list[tuple] = None, impact_categories_units: dict[tuple] = None, filename: str = None, saving_format: str = 'png', saving_path: str = None, show_plot: bool = True) None[source]
Plot LCA indicators for a set of resources for a set of impact categories.
- Parameters:
resources_list (list[str]) – list of technologies to plot. They should have the same operation/infrastructure units to have a meaningful comparison
impact_categories_list (list[tuple]) – list of impact category to plot (brightway format). Not needed if impact_categories_units is provided.
impact_categories_units (dict[tuple]) – dictionary with physical units for each impact category. Not needed if the impact categories are available in the current brightway project.
filename (str) – name of the file to save the plot. If None, the plot is not saved.
saving_format (str) – format to save the plot, can be ‘png’, ‘jpeg’, ‘pdf’, ‘html’, etc. Default is ‘png’.
saving_path (str) – path to save the plot under the form ‘path/to/folder/’. If None, the plot is saved in the current directory.
show_plot (bool) – if True, the plot is shown in the notebook.
- Returns:
None (plot is shown and/or saved)
- Return type:
None
- plot_indicators_of_technologies_for_one_impact_category(technologies_list: list[str], impact_category: tuple, metadata: dict = None, filename: str = None, saving_format: str = 'png', saving_path: str = None, show_plot: bool = True, contributions_total_score: bool = False) None[source]
Plot operation and infrastructure LCA indicators for a set of technologies for a given impact category. If decommission scores are provided, they wil be accounted in the infrastructure scores.
- Parameters:
technologies_list (list[str]) – list of technologies to plot. They should have the same operation/infrastructure units to have a meaningful comparison
impact_category (tuple) – impact category to plot (brightway format)
metadata (dict) – dictionary with metadata to include in the plot. It can include ‘technologies_type’, ‘operation_unit’, ‘construction_unit’, ‘impact_category_unit’.
filename (str) – name of the file to save the plot. If None, the plot is not saved.
saving_format (str) – format to save the plot, can be ‘png’, ‘jpeg’, ‘pdf’, ‘html’, etc. Default is ‘png’.
saving_path (str) – path to save the plot under the form ‘path/to/folder/’. If None, the plot is saved in the current directory.
show_plot (bool) – if True, the plot is shown in the notebook.
contributions_total_score (bool) – if True, the contributions of all categories to the total score are shown.
- Returns:
None (plot is shown and/or saved)
- Return type:
None
- plot_indicators_of_technologies_for_several_impact_categories(technologies_list: list[str], impact_categories_list: list[tuple] = None, impact_categories_units: dict[tuple] = None, filename: str = None, saving_format: str = 'png', saving_path: str = None, show_plot: bool = True) None[source]
Plot operation and infrastructure LCA indicators for a set of technologies for a set of impact categories. If decommission scores are provided, they wil be accounted in the infrastructure scores.
- Parameters:
technologies_list (list[str]) – list of technologies to plot. They should have the same operation/infrastructure units to have a meaningful comparison
impact_categories_list (list[tuple]) – list of impact category to plot (brightway format). Not needed if impact_categories_units is provided.
impact_categories_units (dict[tuple]) – dictionary with physical units for each impact category. Not needed if the impact categories are available in the current brightway project.
filename (str) – name of the file to save the plot. If None, the plot is not saved.
saving_format (str) – format to save the plot, can be ‘png’, ‘jpeg’, ‘pdf’, ‘html’, etc. Default is ‘png’.
saving_path (str) – path to save the plot under the form ‘path/to/folder/’. If None, the plot is saved in the current directory.
show_plot (bool) – if True, the plot is shown in the notebook.
- Returns:
None (plot is shown and/or saved)
- Return type:
None
- plot_results(impact_categories_list: list[tuple] = None, impact_categories_units: dict[tuple] = None, split_by: str = 'Type', N_highest_contributors: int = 0, normalized: bool = False, n_run: int = 0, filename: str = None, saving_format: str = 'png', saving_path: str = None, show_plot: bool = True) None[source]
Plot the environmental impact results
- Parameters:
impact_categories_list (list[tuple]) – list of impact categories to plot (brightway format). Not needed if impact_categories_units is provided.
impact_categories_units (dict[tuple]) – dictionary with physical units for each impact category. Not needed if the impact categories are available in the current brightway project.
split_by (str) – can be ‘Type’ (for life-cycle phases) or ‘Name’ (for technologies and resources)
N_highest_contributors (int) – if split_by is ‘Name’, the number of highest contributors to show
normalized (bool) – if True, the impacts are normalized by the total impact of the category
n_run (int) – number of the run to plot
filename (str) – name of the file to save the plot. If None, the plot is not saved.
saving_format (str) – format to save the plot, can be ‘png’, ‘jpeg’, ‘pdf’, ‘html’, etc. Default is ‘png’.
saving_path (str) – path to save the plot under the form ‘path/to/folder/’. If None, the plot is saved in the current directory.
show_plot (bool) – if True, the plot is shown in the notebook.
- Returns:
None (plot is shown and/or saved)
- Return type:
None
- mescal.plot.plot_contribution_analysis(df: pandas.DataFrame, unit_type_groups_dict: dict, contribution_type: str = 'processes', impact_categories_list: list[str] = None, act_types: list[str] = None, saving_path: str = None, saving_format: str = 'png', show_plot: bool = False, esm_units: list[str] = None, threshold: float = 0.05, cell_size: float = 0.8, min_fig_width: float = 10, min_fig_height: float = 6, dpi: int = 300, annot_fmt: str = '.1%') None[source]
Generate heatmap visualizations for contribution analysis
- Parameters:
df (pandas.DataFrame) – Processed contribution data with impact_share column
unit_type_groups_dict (dict) – Mapping of (ESM, Type) to technology names
contribution_type (str) – Type of contribution analysis: ‘processes’ or ‘emissions’
impact_categories_list (list[str]) – List of impact categories to plot. If None, plots all categories.
act_types (list[str]) – List of activity types. If None, includes all types present in the data.
saving_path (str) – Output directory for saving plots. If None, plots are not saved.
saving_format (str) – Format for saved plots (e.g., ‘png’, ‘pdf’)
show_plot (bool) – Whether to display plots in the notebook
esm_units (list[str]) – List of ESM units to include. If None, includes all available units.
threshold (float) – Threshold for grouping small contributions into ‘Others’
cell_size (float) – Size per cell in inches for figure sizing
min_fig_width (float) – Minimum figure width in inches
min_fig_height (float) – Minimum figure height in inches
dpi (int) – Resolution for saved figures
annot_fmt (str) – Format string for heatmap annotations
- Returns:
None (plots are shown and/or saved)
- Return type:
None