spectrochempy.plot_scree
- plot_scree(explained, cumulative=None, *, ax=None, clear=True, title='Scree plot', bar_color='tab:blue', line_color='tab:orange', show=True)[source]
Plot a scree plot with explained variance bars and cumulative curve.
Creates a scree plot showing individual explained variance as bars on the left y-axis and cumulative explained variance as a line on the right y-axis (twinx).
- Parameters:
explained (array-like) – Explained variance values (as percentages) for each component.
cumulative (array-like, optional) – Cumulative explained variance values (as percentages). If None, computed from
np.cumsum(explained).ax (matplotlib.axes.Axes, optional) – Axes to plot on. If None, a new figure is created.
clear (bool, optional) – Whether to clear the axes before plotting. Default: True. Only used when
axis provided.title (str or None, optional) – Plot title. Default: “Scree plot”. If None, no title is set.
bar_color (color, optional) – Color for the bar plot. Default: “tab:blue”.
line_color (color, optional) – Color for the cumulative line. Default: “tab:orange”.
show (bool, optional) – Whether to display the figure. Default: True.
- Returns:
matplotlib.axes.Axes – The primary axes (left y-axis with bars).
Examples
>>> import numpy as np >>> from spectrochempy import plot_scree >>> explained = np.array([40.0, 25.0, 15.0, 10.0, 5.0, 3.0, 2.0]) >>> ax = plot_scree(explained, show=False)