openpytea.plotting

openpytea.plotting.plot_stacked_bar(data, figsize=(1.2, 1.8), ax=None, show=True)[source]

Create a stacked bar chart with sorted components. This function generates a stacked bar chart where components are sorted by their total values across all bars in descending order. Components are color-coded and displayed with a legend. :param data: Dictionary containing the following keys:

  • “values”list of lists

    List of lists where each inner list contains values for a component across all bars.

  • “labels”tuple or list

    Labels for each component/stack in the bar chart.

  • “xlabels”list

    Labels for the x-axis (one per bar).

  • “currency”str

    Currency symbol or unit to display in y-axis label (ignored if pct=True).

  • “pct”bool

    If True, values are interpreted as percentages and displayed accordingly.

  • “ylabel”str

    Label for the y-axis.

Parameters:
  • figsize (tuple of float, optional) – Figure size as (width, height) in inches. Default is (1.2, 1.8). The width is automatically adjusted based on the number of bars.

  • ax (matplotlib.axes.Axes, optional) – Existing axes object to plot on. If None, a new figure and axes are created. Default is None.

  • show (bool, optional) – If True and a new figure is created, display the plot. Default is True.

Returns:

The axes object containing the stacked bar chart.

Return type:

matplotlib.axes.Axes

Notes

  • Components are sorted in descending order by their total value across

    all bars.

  • Bar spacing is set to 0.75 and bar width is 0.45.

  • Colors are automatically assigned from a colormap and consistent across

    bars.

  • The legend is positioned to the right of the plot area.

  • When pct=True and n_bars=1, the percentage value is appended to the

    component label.

openpytea.plotting.plot_sensitivity(data, figsize=(3.2, 2.2), ax=None, show=True)[source]

Plot sensitivity analysis curves. :param data: Dictionary containing plot data with the following keys:

  • ‘curves’list of dict

    List of curve dictionaries, each containing: - ‘x’ : array-like

    X-axis values for the curve

    • ‘y’array-like

      Y-axis values for the curve

    • ‘plant’str

      Label/name for the curve legend

  • ‘xlabel’str

    Label for the x-axis

  • ‘ylabel’str

    Label for the y-axis

Parameters:
  • figsize (tuple, optional) – Figure size as (width, height) in inches. Default is (3.2, 2.2).

  • ax (matplotlib.axes.Axes, optional) – Axes object to plot on. If None, a new figure and axes are created. Default is None.

  • show (bool, optional) – Whether to display the plot. Default is True.

Returns:

The axes object containing the plotted sensitivity curves.

Return type:

matplotlib.axes.Axes

Notes

  • Multiple curves are plotted with colors from the Set2 colormap.

  • If a new figure is created, tight_layout() is applied before showing.

  • If an existing axes is provided, canvas is redrawn instead of calling

    plt.show().

openpytea.plotting.plot_tornado(data, figsize=(3.4, 2.4), ax=None, show=True)[source]

Create a tornado plot visualization for sensitivity analysis. A tornado plot displays the impact of parameter variations on a base value, showing positive and negative deviations as horizontal bars. :param data: Dictionary containing the following keys:

  • ‘lows’array-like

    Lower bound values for each parameter.

  • ‘highs’array-like

    Upper bound values for each parameter.

  • ‘base_value’float

    Reference/baseline value for comparison.

  • ‘labels’list of str

    Parameter names for y-axis labels.

  • ‘xlabel’str, optional

    Label for x-axis. If None, no label is set.

  • ‘plus_minus_value’float, optional

    Percentage variation value displayed in legend (e.g., 0.1 for 10%).

Parameters:
  • figsize (tuple, optional) – Figure size as (width, height) in inches. Default is (3.4, 2.4).

  • ax (matplotlib.axes.Axes, optional) – Existing axes object to plot on. If None, a new figure and axes are created. Default is None.

  • show (bool, optional) – If True and a new figure is created, display the plot using plt.show(). Default is True.

Returns:

The axes object containing the tornado plot.

Return type:

matplotlib.axes.Axes

Notes

  • Blue bars represent negative deviations (lows from base_value).

  • Red bars represent positive deviations (highs from base_value).

  • A dashed black line indicates the base_value on the x-axis.

  • Automatic padding is applied to x-axis limits (5% of span or range).

openpytea.plotting.plot_monte_carlo(data, metric=None, bins=30, label=None, figsize=(3.2, 2.2), ax=None, show=True)[source]

Plot a histogram with a fitted normal distribution overlay for Monte Carlo simulation results. This function visualizes Monte Carlo data by displaying a histogram of sample values overlaid with a normal distribution curve fitted to the data. It supports multiple input types: Monte Carlo data dictionaries, Plant objects with monte_carlo_metrics, or raw numpy arrays. :param data: The Monte Carlo data to plot. Can be:

  • A dictionary containing a “metrics” key with metric values

  • A Plant object with a monte_carlo_metrics attribute

  • A list or tuple of Plant objects

  • A raw array-like of numeric values

Parameters:
  • metric (str, optional) – The name of the metric to plot (case-insensitive). Default is “LCOP”. Must be present in the data’s available metrics.

  • bins (int, optional) – Number of histogram bins. Default is 30.

  • label (str or None, optional) – X-axis label. If None, a default label is generated based on the metric and currency. Default is None.

  • figsize (tuple, optional) – Figure size as (width, height) in inches. Default is (3.2, 2.2).

  • ax (matplotlib.axes.Axes, optional) – Existing matplotlib axes to plot on. If None, a new figure and axes are created. Default is None.

  • show (bool, optional) – Whether to display the plot using plt.show(). Only applies if a new figure was created. Default is True.

Returns:

The axes object containing the plot.

Return type:

matplotlib.axes.Axes

Raises:

ValueError – If the specified metric is not found in the input data’s available metrics.

Notes

  • The normal distribution parameters (μ, σ) are fitted to the data using

scipy.stats.norm.fit() - The standard deviation is formatted in scientific notation if |σ|>= 1000 or < 0.001 - The histogram is semi-transparent (alpha=0.6) with black edges for better visibility - Colors are cycled from matplotlib’s tab10 colormap for histogram and distribution curve

openpytea.plotting.plot_monte_carlo_inputs(data, figsize=None, bins=50, show=True)[source]

Plot histograms of Monte Carlo input parameters. This function creates a grid of histograms visualizing the distribution of input parameters from a Monte Carlo simulation. Each parameter is displayed in its own subplot, arranged in a grid layout with 3 columns. :param data: Input data containing Monte Carlo parameters. Can be either:

  • A dictionary with an “inputs” key containing the parameters dict

  • A dictionary directly mapping parameter names to arrays of values

Parameters:
  • inputs (dict) – Dictionary where keys are parameter names (str) and values are array like objects containing the parameter samples.

  • figsize (tuple of (float, float), optional) – Figure size as (width, height) in inches. If None, automatically calculated based on number of parameters (default: None).

  • bins (int, optional) – Number of histogram bins for each parameter (default: 50).

  • show (bool, optional) – If True, displays the figure and calls tight_layout(). If False, only returns the axes without displaying (default: True).

Returns:

Array of matplotlib Axes objects corresponding to each subplot. For a single parameter, returns a 1D array; for multiple parameters, returns a flattened array of subplots.

Return type:

numpy.ndarray

Notes

  • Histograms are plotted with density normalization enabled

  • Unused subplots (when n_params is not a multiple of 3) are hidden

  • Each histogram is displayed with black edges and 70% transparency

openpytea.plotting.plot_multiple_monte_carlo(data_list, metric='LCOP', bins=30, figsize=None, label=None, ax=None, show=True)[source]

Plot multiple Monte Carlo simulation results as overlaid histograms with fitted normal distributions.

Parameters:
  • data_list (list of dict or list of Plant) – List of Monte Carlo data dictionaries or Plant objects.

  • metric (str, optional) – Metric to plot from Monte Carlo results (default: “LCOP”).

  • bins (int, optional) – Number of histogram bins (default: 30).

  • figsize (tuple, optional) – Figure size as (width, height).

  • label (str, optional) – Label for the x-axis.

  • ax (matplotlib.axes.Axes, optional) – Axes object to plot on.

  • show (bool, optional) – Whether to display the plot.

Return type:

matplotlib.axes.Axes