clophfit.fitting.plotting#
Provide utilities for creating various types of plots used in this project.
Primary functions encompassed are:
plot_spectra: Develops a plot for spectral data. Each line is colored based on a designated colormap. plot_autovectors: Plots the autovectors. plot_autovalues: Plots the singular values from SVD. plot_fit: Plots residuals for each dataset with uncertainty. plot_pca: Plots the first two principal components. plot_spectra_distributed: Plots spectra from titration distributing on the figure top. plot_emcee: Plots emcee result. plot_emcee_k_on_ax: Plots emcee result for a specific parameter on an axis. distribute_axes: Positions axes evenly along the horizontal axis of the figure.
The module uses several dependencies such as ArviZ, numpy, pandas, seaborn, lmfit, matplotlib, and uncertainties. Moreover, it includes a range of internal project modules and a specific color map for PCA components and LM fit.
Helper Functions:
_apply_common_plot_style: Applies grid style, title, and labels to a plot. _create_spectra_canvas: Creates figure and axes for spectra plot.
Classes:
PlotParameters: Parameters for plotting, depending on whether the data is pH or Cl.
Classes#
Parameters for plotting, depending on whether the data is pH or Cl. |
Functions#
|
Position axes evenly along the horizontal axis of the figure. |
|
Plot the singular values from SVD. |
|
Plot autovectors. |
|
Plot the first two principal components. |
|
Plot spectra. |
|
Plot spectra from titration distributing on the top of the figure top. |
|
Plot standard deviation versus mean of inferred sigma for quality control. |
|
Plot emcee result. |
|
Plot emcee result. |
|
Plot fitted curves and data points with uncertainty on a given Axes. |
|
Plot fitted curves and data points on a given axis. |
|
Print maximum likelihood estimation (MLE) results from an emcee fitting. |
|
Extract heteroscedastic sigma summaries from a PyMC trace. |
|
Plot signal span versus center for quality control of titration wells. |
|
Plot signal span versus center for quality control using a Titration object. |
Module Contents#
- class clophfit.fitting.plotting.PlotParameters#
Parameters for plotting, depending on whether the data is pH or Cl.
- clophfit.fitting.plotting.distribute_axes(fig, num_axes)#
Position axes evenly along the horizontal axis of the figure.
- Parameters:
fig (Figure) – The Figure object on which the Axes objects are drawn.
num_axes (int) – The number of Axes objects to position.
- Returns:
A list of positioned Axes objects.
- Return type:
list[Axes]
- clophfit.fitting.plotting.plot_autovalues(ax, s)#
Plot the singular values from SVD.
- Parameters:
ax (Axes) – The mpl.axes.axes on which to plot the singular values.
s (ArrayF) – The singular values from the SVD.
- Return type:
None
- clophfit.fitting.plotting.plot_autovectors(ax, wl, u)#
Plot autovectors.
- Parameters:
ax (Axes) – The mpl.axes.Axes object to which the plot should be added.
wl (pd.Index[int]) – The index of spectra data frame.
u (ArrayF) – The left singular vectors obtained from SVD.
- Return type:
None
- clophfit.fitting.plotting.plot_pca(ax, v, conc, pp)#
Plot the first two principal components.
- Parameters:
ax (Axes) – The mpl.axes.Axes object to which the plot should be added.
v (ArrayF) – The matrix containing the principal components.
conc (ArrayF) – The concentrations used for the titration.
pp (PlotParameters) – The PlotParameters object containing plot parameters.
- Return type:
None
- clophfit.fitting.plotting.plot_spectra(ax, spectra, pp)#
Plot spectra.
- Parameters:
ax (Axes) – The Mpl.Axes.Axes object to which the plot should be added.
spectra (pd.DataFrame) – The DataFrame containing spectral data.
pp (PlotParameters) – The PlotParameters object containing plot parameters.
- Return type:
None
- clophfit.fitting.plotting.plot_spectra_distributed(fig, titration, pp, dbands=None)#
Plot spectra from titration distributing on the top of the figure top.
- Parameters:
fig (matplotlib.figure.Figure)
titration (dict[str, pandas.DataFrame])
pp (PlotParameters)
dbands (dict[str, tuple[int, int]] | None)
- Return type:
None
- clophfit.fitting.plotting.plot_qc_mean_vs_std(trace, results=None, figsize_per_label=(5, 4), annotate_wells=None, z_threshold=3.0, bg_noise=None, bg_multiplier=4.0)#
Plot standard deviation versus mean of inferred sigma for quality control.
Identifies “dead” or flat-line wells (e.g. caused by pipetting errors or missing fluorophore) which typically exhibit both low mean and low span (max - min) for the inferred standard deviation (sigma_obs) across titration steps.
- Parameters:
trace (xr.DataTree) – The PyMC inference trace containing sigma_obs deterministic nodes.
results (Mapping[str, FitResult[MiniT]] | None, optional) – The dictionary of well results to derive fallback sigma values.
figsize_per_label (tuple[float, float], optional) – Figure size allocated for each spectral band (label). Default is (5, 4).
annotate_wells (list[str] | None, optional) – A list of specific well IDs to annotate on the plot (e.g., [“B03”, “C05”]). If None, no explicit labels are drawn.
z_threshold (float) – Z-score threshold for identifying outliers.
bg_noise (Mapping[str, float] | None, optional) – Background noise dictionary.
bg_multiplier (float) – Multiplier for background noise.
- Returns:
The generated QC matplotlib figure.
- Return type:
Figure
- clophfit.fitting.plotting.plot_emcee(flatchain)#
Plot emcee result.
- Parameters:
flatchain (pandas.DataFrame)
- Return type:
matplotlib.figure.Figure
- clophfit.fitting.plotting.plot_emcee_k_on_ax(ax, res_emcee, p_name='K')#
Plot emcee result.
- Parameters:
ax (matplotlib.axes.Axes)
res_emcee (lmfit.minimizer.MinimizerResult)
p_name (str)
- Return type:
None
- clophfit.fitting.plotting.plot_fit(ax, ds, params, nboot=0, pp=None)#
Plot fitted curves and data points with uncertainty on a given Axes.
- Parameters:
ax (Axes) – The matplotlib axis to plot on.
ds (Dataset) – The dataset containing the data points.
params (Parameters) – The fitted parameters from lmfit.
nboot (int) – Number of bootstrap samples to generate confidence bands.
pp (PlotParameters | None) – Plotting parameters for consistent styling.
- Return type:
None
- clophfit.fitting.plotting.plot_fit_gemini(ax, ds, params, nboot=0, pp=None)#
Plot fitted curves and data points on a given axis.
- Parameters:
ax (axes.Axes) – The matplotlib axis to plot on.
ds (Dataset) – The dataset containing the data points.
params (Parameters) – The fitted parameters from lmfit.
nboot (int) – Number of bootstrap samples to generate confidence bands.
pp (PlotParameters | None) – Plotting parameters for consistent styling.
- Return type:
None
- clophfit.fitting.plotting.print_emcee(result_emcee)#
Print maximum likelihood estimation (MLE) results from an emcee fitting.
- Parameters:
result_emcee (lmfit.minimizer.MinimizerResult)
- Return type:
None
- clophfit.fitting.plotting.extract_sigma_df(trace, results=None)#
Extract heteroscedastic sigma summaries from a PyMC trace.
- Parameters:
trace (xarray.DataTree)
results (collections.abc.Mapping[str, clophfit.fitting.data_structures.FitResult[clophfit.fitting.data_structures.MiniT]] | None)
- Return type:
pandas.DataFrame
- clophfit.fitting.plotting.plot_qc_span_vs_center(data, center='mean', figsize_per_label=(5, 4), z_threshold=3.0, bg_noise=None, bg_multiplier=4.0, loglog=False, annotate_wells=None)#
Plot signal span versus center for quality control of titration wells.
Identifies dead or flat wells (e.g. caused by pipetting errors or missing fluorophore) which show low dynamic range relative to their signal center.
- Parameters:
data (Mapping[int, Mapping[str, ArrayF]]) – Raw or normalised data keyed by label index, then by well name.
center (str) – How to compute the x-axis value per well:
"mean"(default) or"max"(maximum absolute signal).figsize_per_label (tuple[float, float]) – Figure size allocated per spectral label.
z_threshold (float) – Z-score threshold for trendline-based outlier detection.
bg_noise (Mapping[str, float | ArrayF] | Mapping[int, float | ArrayF] | None) – Background noise reference per label (string or integer keys). Used to draw a
bg_multiplier * bg_noisereference line.bg_multiplier (float) – Multiplier applied to
bg_noisefor the low-signal reference.loglog (bool) – If True, use log-log axes.
annotate_wells (list[str] | None) – Well IDs to annotate even if not flagged as outliers.
- Returns:
The generated QC matplotlib figure.
- Return type:
Figure
- clophfit.fitting.plotting.plot_qc_span_vs_center_titration(tit, center='mean', figsize_per_label=(5, 4), z_threshold=3.0, bg_multiplier=4.0, loglog=False, annotate_wells=None)#
Plot signal span versus center for quality control using a Titration object.
Convenience wrapper around
plot_qc_span_vs_center()that extracts data and background noise directly from aTitration.- Parameters:
tit (object) – The titration object.
center (str) – How to compute the x-axis value per well:
"mean"or"max".figsize_per_label (tuple[float, float]) – Figure size per spectral label.
z_threshold (float) – Z-score threshold for trendline outlier detection.
bg_multiplier (float) – Multiplier applied to the background noise reference.
loglog (bool) – If True, use log-log axes.
annotate_wells (list[str] | None) – Well IDs to annotate even if not flagged.
- Returns:
The generated QC matplotlib figure.
- Return type:
Figure