FeatureSelectionPlot#
- class chemotools.plotting.FeatureSelectionPlot(x: ndarray, y: ndarray, support: ndarray, *, selection_color: str = 'red', selection_alpha: float = 0.2, **kwargs: Any)[source]
Bases:
SpectraPlotPlot class for visualizing feature selection on spectral data.
This class extends SpectraPlot to highlight excluded features using colored vertical spans.
- Parameters:
x (np.ndarray) – X-axis data (e.g., wavelengths, wavenumbers).
y (np.ndarray) – Y-axis data (e.g., spectra intensities).
support (np.ndarray) – Boolean mask indicating selected features (True means selected). Must have same length as x.
selection_color (str, optional) – Color to use for highlighting excluded features. Default is “red”.
selection_alpha (float, optional) – Transparency of the selection highlight. Default is 0.2.
**kwargs (Any) – Additional arguments passed to SpectraPlot.__init__.
Attributes
color_byis_categoricalcolormapcolorbar_label- show(figsize=(12, 4), title=None, xlabel='X-axis', ylabel='Y-axis', xlim=None, ylim=None, **kwargs) Figure[source]
Show the spectra plot with given figure size and labels. The excluded features are highlighted with red bars.
- Parameters:
figsize (tuple, optional) – Figure size as (width, height) in inches. Default is (12, 4).
title (str, optional) – Title for the plot. If None, a default title is generated.
xlabel (str, optional) – X-axis label. Default is “X-axis”.
ylabel (str, optional) – Y-axis label. Default is “Y-axis”.
xlim (tuple, optional) – X-axis limits as (xmin, xmax). Default is None (auto).
ylim (tuple, optional) – Y-axis limits as (ymin, ymax). Default is None (auto).
**kwargs (Any) – Additional keyword arguments passed to the plot function.
- Returns:
The matplotlib Figure object containing the plot.
- Return type:
Figure
- render(ax: Axes | None = None, *, xlabel: str | None = None, ylabel: str | None = None, xlim: tuple[float, float] | None = None, ylim: tuple[float, float] | None = None, **kwargs: Any) tuple[Figure, Axes][source]
Render the plot on the given axes or create new ones.
- Parameters:
ax (Axes, optional) – Matplotlib axes to plot on. If None, creates new figure and axes.
xlabel (str, optional) – X-axis label. Default is “X-axis”.
ylabel (str, optional) – Y-axis label. Default is “Y-axis”.
xlim (tuple[float, float], optional) – X-axis limits as (xmin, xmax). When set without ylim, the y-axis automatically scales to fit the data within the x-range.
ylim (tuple[float, float], optional) – Y-axis limits as (ymin, ymax). When provided, disables automatic y-scaling.
**kwargs (Any) – Additional keyword arguments passed to the plot function.
- Returns:
fig (Figure) – The matplotlib Figure object.
ax (Axes) – The matplotlib Axes object with the rendered plot.