Visualization#
- class spectoprep.visualization.plots.SpectroPrepPlotter[source]#
Bases:
objectA class for creating high-quality plots for spectroscopy data.
This class provides various plotting functions specifically designed for spectroscopy data and pipeline optimization results.
- static set_style(style='whitegrid', context='paper', font_scale=1.2)[source]#
Set the visual style for the plots.
- static plot_spectra(wavenumbers, spectra, labels=None, title='Spectral Data', xlabel='Wavenumber (cm$^{-1}$)', ylabel='Absorbance', alpha=0.7, figsize=(12, 6), color_map='viridis', legend_loc='best', grid=True, invert_xaxis=False, save_path=None)[source]#
Plot spectral data.
- Parameters:
wavenumbers (array-like) – The x-axis values (wavenumbers / wavelengths).
spectra (array-like) – The spectra data of shape (n_samples, n_features).
labels (list of str, optional) – Labels for each spectrum. If None, spectra are numbered.
title (str, default='Spectral Data') – Plot title.
xlabel (str, default='Wavenumber (cm$^{-1}$)') – X-axis label.
ylabel (str, default='Absorbance') – Y-axis label.
alpha (float, default=0.7) – Transparency of the lines.
figsize (tuple, default=(12, 6)) – Figure size.
color_map (str, default='viridis') – Colormap for the spectra.
legend_loc (str, default='best') – Location of the legend.
grid (bool, default=True) – Whether to show grid.
invert_xaxis (bool, default=False) – If True, reverse the x-axis (common for IR/NIR displays).
save_path (str, optional) – If provided, save the figure to this path.
- Returns:
fig (matplotlib.figure.Figure) – The figure object.
ax (matplotlib.axes.Axes) – The axes object.
- static plot_preprocessing_comparison(wavenumbers, original_spectra, processed_spectra, sample_indices=None, figsize=(15, 10), title='Preprocessing Comparison', xlabel='Wavenumber (cm$^{-1}$)', color_map='tab10', alpha=0.35, invert_xaxis=False, save_path=None)[source]#
Plot comparison of original and processed spectra.
- Parameters:
wavenumbers (array-like) – The x-axis values (wavenumbers / wavelengths).
original_spectra (array-like) – The original spectra data of shape (n_samples, n_features).
processed_spectra (dict) – Dictionary mapping preprocessing method names to processed spectra.
sample_indices (list of int, optional) – Indices of samples to plot. If None, all samples are plotted.
figsize (tuple, default=(15, 10)) – Figure size.
title (str, default='Preprocessing Comparison') – Main title for the figure.
xlabel (str, default='Wavenumber (cm$^{-1}$)') – X-axis label on the bottom panel.
color_map (str, default='tab10') – Colormap for differentiating samples.
alpha (float, default=0.35) – Line transparency (lower helps when plotting many spectra).
invert_xaxis (bool, default=False) – If True, reverse the x-axis (common for IR/NIR displays).
save_path (str, optional) – If provided, save the figure to this path.
- Returns:
fig – The figure object.
- Return type:
- static plot_optimization_results(optimizer, top_n=5, figsize=(12, 8), title='Pipeline Optimization Results', save_path=None)[source]#
Plot optimization results from PipelineOptimizer.
- Parameters:
optimizer (PipelineOptimizer) – The fitted pipeline optimizer.
top_n (int, default=5) – Number of top pipelines to display.
figsize (tuple, default=(12, 8)) – Figure size.
title (str, default='Pipeline Optimization Results') – Plot title.
save_path (str, optional) – If provided, save the figure to this path.
- Returns:
fig – The figure object.
- Return type:
- static plot_prediction_scatter(y_true, y_pred, title='Prediction Performance', xlabel='Measured', ylabel='Predicted', figsize=(10, 8), alpha=0.7, color='blue', add_metrics=True, save_path=None)[source]#
Create a scatter plot of predicted vs true values.
- Parameters:
y_true (array-like) – True target values.
y_pred (array-like) – Predicted target values.
title (str, default='Prediction Performance') – Plot title.
xlabel (str, default='Measured') – X-axis label.
ylabel (str, default='Predicted') – Y-axis label.
figsize (tuple, default=(10, 8)) – Figure size.
alpha (float, default=0.7) – Transparency of the points.
color (str, default='blue') – Color of the scatter points.
add_metrics (bool, default=True) – Whether to add RMSE and R² metrics to the plot.
save_path (str, optional) – If provided, save the figure to this path.
- Returns:
fig (matplotlib.figure.Figure) – The figure object.
ax (matplotlib.axes.Axes) – The axes object.
- static plot_optimization_progress(optimizer, figsize=(12, 6), title='Optimization Progress', save_path=None)[source]#
Plot optimization progress over iterations.
- Parameters:
optimizer (PipelineOptimizer) – The fitted pipeline optimizer.
figsize (tuple, default=(12, 6)) – Figure size.
title (str, default='Optimization Progress') – Plot title.
save_path (str, optional) – If provided, save the figure to this path.
- Returns:
fig (matplotlib.figure.Figure) – The figure object.
ax (matplotlib.axes.Axes) – The axes object.
- static plot_feature_importance(wavenumbers, coefficients, title='Feature Importance', xlabel='Wavenumber (cm$^{-1}$)', ylabel='Coefficient Value', figsize=(12, 6), color='purple', highlight_threshold=None, highlight_color='red', save_path=None)[source]#
Plot feature importance from model coefficients.
- Parameters:
wavenumbers (array-like) – The x-axis values (wavenumbers).
coefficients (array-like) – Model coefficients corresponding to each wavenumber.
title (str, default='Feature Importance') – Plot title.
xlabel (str, default='Wavenumber (cm$^{-1}$)') – X-axis label.
ylabel (str, default='Coefficient Value') – Y-axis label.
figsize (tuple, default=(12, 6)) – Figure size.
color (str, default='purple') – Color of the line.
highlight_threshold (float, optional) – If provided, highlights coefficients with absolute values above this threshold.
highlight_color (str, default='red') – Color for highlighted coefficients.
save_path (str, optional) – If provided, save the figure to this path.
- Returns:
fig (matplotlib.figure.Figure) – The figure object.
ax (matplotlib.axes.Axes) – The axes object.