clophfit.fitting.plotting ========================= .. py:module:: clophfit.fitting.plotting .. autoapi-nested-parse:: 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 ------- .. autoapisummary:: clophfit.fitting.plotting.PlotParameters Functions --------- .. autoapisummary:: clophfit.fitting.plotting.distribute_axes clophfit.fitting.plotting.plot_autovalues clophfit.fitting.plotting.plot_autovectors clophfit.fitting.plotting.plot_pca clophfit.fitting.plotting.plot_spectra clophfit.fitting.plotting.plot_spectra_distributed clophfit.fitting.plotting.plot_qc_mean_vs_std clophfit.fitting.plotting.plot_emcee clophfit.fitting.plotting.plot_emcee_k_on_ax clophfit.fitting.plotting.plot_fit clophfit.fitting.plotting.plot_fit_gemini clophfit.fitting.plotting.print_emcee clophfit.fitting.plotting.extract_sigma_df clophfit.fitting.plotting.plot_qc_span_vs_center clophfit.fitting.plotting.plot_qc_span_vs_center_titration Module Contents --------------- .. py:class:: PlotParameters Parameters for plotting, depending on whether the data is pH or Cl. .. py:function:: distribute_axes(fig, num_axes) Position axes evenly along the horizontal axis of the figure. :param fig: The Figure object on which the Axes objects are drawn. :type fig: Figure :param num_axes: The number of Axes objects to position. :type num_axes: int :returns: A list of positioned Axes objects. :rtype: list[Axes] .. py:function:: plot_autovalues(ax, s) Plot the singular values from SVD. :param ax: The mpl.axes.axes on which to plot the singular values. :type ax: Axes :param s: The singular values from the SVD. :type s: ArrayF .. py:function:: plot_autovectors(ax, wl, u) Plot autovectors. :param ax: The mpl.axes.Axes object to which the plot should be added. :type ax: Axes :param wl: The index of spectra data frame. :type wl: pd.Index[int] :param u: The left singular vectors obtained from SVD. :type u: ArrayF .. py:function:: plot_pca(ax, v, conc, pp) Plot the first two principal components. :param ax: The mpl.axes.Axes object to which the plot should be added. :type ax: Axes :param v: The matrix containing the principal components. :type v: ArrayF :param conc: The concentrations used for the titration. :type conc: ArrayF :param pp: The PlotParameters object containing plot parameters. :type pp: PlotParameters .. py:function:: plot_spectra(ax, spectra, pp) Plot spectra. :param ax: The Mpl.Axes.Axes object to which the plot should be added. :type ax: Axes :param spectra: The DataFrame containing spectral data. :type spectra: pd.DataFrame :param pp: The PlotParameters object containing plot parameters. :type pp: PlotParameters .. py:function:: plot_spectra_distributed(fig, titration, pp, dbands = None) Plot spectra from titration distributing on the top of the figure top. .. py:function:: 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. :param trace: The PyMC inference trace containing `sigma_obs` deterministic nodes. :type trace: xr.DataTree :param results: The dictionary of well results to derive fallback sigma values. :type results: Mapping[str, FitResult[MiniT]] | None, optional :param figsize_per_label: Figure size allocated for each spectral band (label). Default is (5, 4). :type figsize_per_label: tuple[float, float], optional :param annotate_wells: A list of specific well IDs to annotate on the plot (e.g., ["B03", "C05"]). If None, no explicit labels are drawn. :type annotate_wells: list[str] | None, optional :param z_threshold: Z-score threshold for identifying outliers. :type z_threshold: float :param bg_noise: Background noise dictionary. :type bg_noise: Mapping[str, float] | None, optional :param bg_multiplier: Multiplier for background noise. :type bg_multiplier: float :returns: The generated QC matplotlib figure. :rtype: Figure .. py:function:: plot_emcee(flatchain) Plot emcee result. .. py:function:: plot_emcee_k_on_ax(ax, res_emcee, p_name = 'K') Plot emcee result. .. py:function:: plot_fit(ax, ds, params, nboot = 0, pp = None) Plot fitted curves and data points with uncertainty on a given Axes. :param ax: The matplotlib axis to plot on. :type ax: Axes :param ds: The dataset containing the data points. :type ds: Dataset :param params: The fitted parameters from lmfit. :type params: Parameters :param nboot: Number of bootstrap samples to generate confidence bands. :type nboot: int :param pp: Plotting parameters for consistent styling. :type pp: PlotParameters | None .. py:function:: plot_fit_gemini(ax, ds, params, nboot = 0, pp = None) Plot fitted curves and data points on a given axis. :param ax: The matplotlib axis to plot on. :type ax: axes.Axes :param ds: The dataset containing the data points. :type ds: Dataset :param params: The fitted parameters from lmfit. :type params: Parameters :param nboot: Number of bootstrap samples to generate confidence bands. :type nboot: int :param pp: Plotting parameters for consistent styling. :type pp: PlotParameters | None .. py:function:: print_emcee(result_emcee) Print maximum likelihood estimation (MLE) results from an emcee fitting. .. py:function:: extract_sigma_df(trace, results = None) Extract heteroscedastic sigma summaries from a PyMC trace. .. py:function:: 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. :param data: Raw or normalised data keyed by label index, then by well name. :type data: Mapping[int, Mapping[str, ArrayF]] :param center: How to compute the x-axis value per well: ``"mean"`` (default) or ``"max"`` (maximum absolute signal). :type center: str :param figsize_per_label: Figure size allocated per spectral label. :type figsize_per_label: tuple[float, float] :param z_threshold: Z-score threshold for trendline-based outlier detection. :type z_threshold: float :param bg_noise: Background noise reference per label (string or integer keys). Used to draw a ``bg_multiplier * bg_noise`` reference line. :type bg_noise: Mapping[str, float | ArrayF] | Mapping[int, float | ArrayF] | None :param bg_multiplier: Multiplier applied to ``bg_noise`` for the low-signal reference. :type bg_multiplier: float :param loglog: If True, use log-log axes. :type loglog: bool :param annotate_wells: Well IDs to annotate even if not flagged as outliers. :type annotate_wells: list[str] | None :returns: The generated QC matplotlib figure. :rtype: Figure .. py:function:: 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 :func:`plot_qc_span_vs_center` that extracts data and background noise directly from a :class:`~clophfit.prtecan.Titration`. :param tit: The titration object. :type tit: object :param center: How to compute the x-axis value per well: ``"mean"`` or ``"max"``. :type center: str :param figsize_per_label: Figure size per spectral label. :type figsize_per_label: tuple[float, float] :param z_threshold: Z-score threshold for trendline outlier detection. :type z_threshold: float :param bg_multiplier: Multiplier applied to the background noise reference. :type bg_multiplier: float :param loglog: If True, use log-log axes. :type loglog: bool :param annotate_wells: Well IDs to annotate even if not flagged. :type annotate_wells: list[str] | None :returns: The generated QC matplotlib figure. :rtype: Figure