Plotting Module
This module provides plotting utilities for visualizing sampling results, including trace plots, corner plots, and parameter summaries.
Plotting utilities for discoverysamplers.
This module provides common plotting functions that are used across all sampler interfaces. Each interface provides lightweight wrappers around these functions.
Available Plots
Trace plots: Show parameter evolution over samples/steps
Corner plots: Show marginal distributions and correlations
Run plots: Diagnostic plots for nested sampling runs
All functions accept a standardized samples dictionary with keys: - ‘names’: list of parameter names - ‘labels’: list of LaTeX labels for plotting - ‘chain’: numpy array of samples
For MCMC chains (Eryn), the chain shape is typically (nsteps, ntemps, nwalkers, nleaves, ndim). For nested sampling (Nessai, JAX-NS), the chain is (nsamples, ndim).
- discoverysamplers.plots.plot_trace(samples, *, burn=0, fixed_params=None, fixed_names=None, figsize=None, alpha=0.3, lw=0.7, colors=None, title=None)[source]
Create trace plots showing parameter evolution over samples.
- Parameters:
samples (dict) – Dictionary with keys ‘names’, ‘labels’, ‘chain’. Chain can be: - (nsteps, ntemps, nwalkers, [nleaves,] ndim) for MCMC - (nsamples, ndim) for nested sampling
burn (int, optional) – Number of initial samples to discard, by default 0.
fixed_params (dict, optional) – Dictionary of fixed parameter values to show as horizontal lines.
fixed_names (list, optional) – Names of fixed parameters (to identify which to mark).
figsize (tuple, optional) – Figure size (width, height). Auto-scaled if None.
alpha (float, optional) – Transparency for trace lines, by default 0.3.
lw (float, optional) – Line width, by default 0.7.
colors (list, optional) – Colors for different temperatures/chains. Uses matplotlib defaults if None.
title (str, optional) – Figure title.
- Returns:
Figure containing the trace plots.
- Return type:
matplotlib.figure.Figure
Examples
>>> samples = bridge.return_sampled_samples() >>> fig = plot_trace(samples, burn=1000) >>> fig.savefig('trace.pdf')
- discoverysamplers.plots.plot_corner(samples, *, burn=0, temp=0, truths=None, quantiles=None, show_titles=True, title_fmt='.3f', **corner_kwargs)[source]
Create a corner plot showing marginal distributions and correlations.
- Parameters:
samples (dict) – Dictionary with keys ‘names’, ‘labels’, ‘chain’.
burn (int, optional) – Number of initial samples to discard, by default 0.
temp (int, optional) – Temperature index for MCMC chains (0 = cold chain), by default 0.
truths (sequence, optional) – True parameter values to mark on the plot.
quantiles (sequence, optional) – Quantiles to show on 1D histograms. Default is [0.16, 0.5, 0.84].
show_titles (bool, optional) – Show parameter estimates in titles, by default True.
title_fmt (str, optional) – Format string for title values, by default “.3f”.
**corner_kwargs – Additional keyword arguments passed to corner.corner().
- Returns:
Corner plot figure.
- Return type:
matplotlib.figure.Figure
Examples
>>> samples = bridge.return_sampled_samples() >>> fig = plot_corner(samples, burn=1000, quantiles=[0.16, 0.5, 0.84]) >>> fig.savefig('corner.pdf')
- discoverysamplers.plots.plot_corner_multi_temp(samples, *, burn=0, temps=None, **corner_kwargs)[source]
Create corner plots for multiple temperatures (MCMC only).
- Parameters:
samples (dict) – Dictionary with keys ‘names’, ‘labels’, ‘chain’. Chain must have shape (nsteps, ntemps, nwalkers, ndim).
burn (int, optional) – Number of initial samples to discard, by default 0.
temps (sequence, optional) – Temperature indices to plot. Default plots all temperatures.
**corner_kwargs – Additional keyword arguments passed to corner.corner().
- Returns:
List of corner plot figures, one per temperature.
- Return type:
list of matplotlib.figure.Figure
- discoverysamplers.plots.plot_run_plot(samples, *, log_evidence=None, log_evidence_err=None, figsize=(10, 6))[source]
Create a run plot showing sampling progress (nested sampling diagnostics).
This plot shows the log-likelihood values vs sample index, which is useful for diagnosing nested sampling convergence.
- Parameters:
- Returns:
Run plot figure.
- Return type:
matplotlib.figure.Figure
- discoverysamplers.plots.plot_nleaves_histogram(nleaves, *, nleaves_min, nleaves_max, true_nleaves=None, temp=0, figsize=(8, 5), title=None)[source]
Plot histogram of number of active components (for RJMCMC).
- Parameters:
nleaves (ndarray) – Array of nleaves values with shape (nsteps, ntemps, nwalkers) or (nsteps, ntemps).
nleaves_min (int) – Minimum number of leaves.
nleaves_max (int) – Maximum number of leaves.
true_nleaves (int, optional) – True number of components to mark on plot.
temp (int, optional) – Temperature index to use (0 = cold chain), by default 0.
figsize (tuple, optional) – Figure size, by default (8, 5).
title (str, optional) – Plot title.
- Returns:
Histogram figure.
- Return type:
matplotlib.figure.Figure
Examples
>>> nleaves = bridge.return_nleaves() >>> fig = plot_nleaves_histogram(nleaves, nleaves_min=1, nleaves_max=5, true_nleaves=2)
- discoverysamplers.plots.plot_parameter_summary(samples, *, burn=0, credible_interval=0.9, figsize=None)[source]
Create a summary plot showing parameter estimates with credible intervals.
- Parameters:
- Returns:
Summary plot figure.
- Return type:
matplotlib.figure.Figure
See Also
Plotting and Visualization - User guide on plotting