Plotting Module
The plotting module handles plot generation and visualization.
Plotting Utilities
Plotting utilities for RegressionLab.
This module provides functions to create pair plots (scatter matrices) and save fitted data plots with error bars, using configuration from config (fonts, style).
- plotting.plot_utils.create_pair_plots(data, variable_names, plot_config=None, font_config=None, output_path=None)[source]
Create a grid of scatter plots for all pairs of variables (pair plot).
- Parameters:
data – DataFrame or dict-like with numeric columns.
variable_names – List of column names to use (must be numeric).
plot_config – Optional plot configuration dict. Defaults to PLOT_CONFIG.
font_config – Optional font configuration dict. Defaults to FONT_CONFIG.
output_path – If given, save figure to this path and return path (str). If None, return the Figure for inline display (e.g. Streamlit).
- Returns:
path to the saved image (str). Otherwise: matplotlib Figure instance.
- Return type:
If output_path is set
- plotting.plot_utils.create_plot(x, y, ux, uy, y_fitted, fit_name, x_name, y_name, plot_config=None, font_config=None, output_path=None, fit_info=None)[source]
Create and save a plot with experimental data and fitted curve.
- Parameters:
x – Independent variable data (array-like).
y – Dependent variable data (array-like).
ux – Uncertainties in x (array-like).
uy – Uncertainties in y (array-like).
y_fitted – Fitted y values (array-like).
fit_name – Name of the fit for plot title.
x_name – Label for x-axis.
y_name – Label for y-axis.
plot_config – Optional plot configuration dict. Defaults to PLOT_CONFIG.
font_config – Optional font configuration dict. Defaults to FONT_CONFIG.
output_path – Optional full path to save the plot. If None, uses get_output_path(fit_name).
fit_info – Optional dict with ‘fit_func’ and ‘params’ to evaluate the curve at linspace points for a smooth plot. If None, uses x and y_fitted directly.
- Returns:
Path to the saved plot file (as string).
- Raises:
OSError – If the plot file cannot be written.
RuntimeError – If matplotlib fails during plot creation or saving.
- plotting.plot_utils.create_residual_plot(residuals, point_indices, fit_name, plot_config=None, font_config=None, output_path=None)[source]
Create a residual plot for multidimensional fitting.
Shows residuals (y - y_fitted) vs point index.
- Parameters:
residuals – Residual values (y - y_fitted) for each data point.
point_indices – Indices of data points (0, 1, 2, …).
fit_name – Name of the fit for plot title.
plot_config – Optional plot configuration dict. Defaults to PLOT_CONFIG.
font_config – Optional font configuration dict. Defaults to FONT_CONFIG.
output_path – Optional full path to save the plot. If None, uses get_output_path(fit_name).
- Returns:
Path to the saved plot file (as string).
- plotting.plot_utils.create_3d_plot(x, y, z, z_fitted, fit_name, x_name, y_name, z_name, plot_config=None, font_config=None, output_path=None, interactive=False, fit_info=None)[source]
Create a 3D plot for fitting with two independent variables.
Shows data points and fitted surface mesh.
- Parameters:
x – First independent variable data.
y – Second independent variable data.
z – Dependent variable data (observed).
z_fitted – Fitted z values.
fit_name – Name of the fit for plot title.
x_name – Label for x-axis.
y_name – Label for y-axis.
z_name – Label for z-axis.
plot_config – Optional plot configuration dict. Defaults to PLOT_CONFIG.
font_config – Optional font configuration dict. Defaults to FONT_CONFIG.
output_path – Optional full path to save the plot. If None, uses get_output_path(fit_name).
interactive – If True, return (save_path, figure) for embedding in a window (rotatable with mouse).
fit_info – Optional dict with ‘fit_func’ and ‘params’ to evaluate the surface on a linspace grid for a smooth plot. If None, interpolates z_fitted onto the grid.
- Returns:
path to the saved plot file (str). If interactive=True: tuple (save_path, figure) for embedding.
- Return type:
If interactive=False