Plotting

Visualization utilities for model fitting results.

socca.plotting.getframe(wcs)[source]

Get axis labels from a WCS object based on its celestial frame.

Parameters:

wcs (astropy.wcs.WCS) – WCS object to extract frame information from.

Returns:

  • xtext (str) – Label for the x-axis (e.g., ‘RA (ICRS)’, ‘Galactic Longitude’).

  • ytext (str) – Label for the y-axis (e.g., ‘Dec (ICRS)’, ‘Galactic Latitude’).

class socca.plotting.Plotter(fit)[source]

Bases: object

Visualization interface for model fitting results.

Provides methods for plotting posterior samples, corner plots, model images, residuals, and other diagnostic visualizations.

__init__(fit)[source]

Initialize the Plotter with a reference to a fitter object.

Parameters:

fit (fitter) – Fitter object containing the model, data, samples, and results to be plotted.

corner(name=None, component=None, fmt='pdf', sigma=10.0, edges=None, quantiles=[0.16, 0.5, 0.84], bins=40, **kwargs)[source]

Create corner plots showing posterior distributions and correlations.

Generates a corner (triangle) plot displaying 1D and 2D marginalized posterior distributions for model parameters. Plots can be customized to show specific components and parameter ranges.

Parameters:
  • name (str, optional) – Output filename (without extension). If None, displays plot interactively instead of saving. Default is None.

  • component (str, int, list, or None, optional) –

    Component(s) to plot. Can be:

    • None: Plot all components (default)

    • str: Single component name (e.g., ‘comp_00’)

    • int: Component index

    • list: Multiple components (names, indices, or objects)

  • fmt (str, optional) – Output file format (e.g., ‘pdf’, ‘png’). Default is ‘pdf’.

  • sigma (float, optional) – Number of standard deviations to use for automatic axis limits. If None, uses full parameter ranges. Default is 10.0.

  • edges (array_like or None, optional) – Explicit axis limits as [[xmin, xmax], …] for each parameter. If None, computed automatically from sigma. Default is None.

  • quantiles (list, optional) – Quantiles to display on 1D histograms. Default is [0.16, 0.5, 0.84] (median and 1-sigma intervals).

  • bins (int, optional) – Number of bins for histograms. Default is 40.

  • **kwargs (dict, optional) – Additional keyword arguments passed to corner.corner(). See corner package documentation for available options.

Notes

  • Automatically handles parameter units in axis labels

  • Uses weighted samples if available from nested sampling

  • Supports truths parameter via kwargs to show true parameter values

comparison(name=None, component=None, fmt='pdf', fx=1.0, fy=0.38, dpi=55.92321428571429, cmaps=None, cmap_data=None, cmap_model=None, cmap_residual=None, gs_kwargs=None, model_kwargs=None)[source]

Create a three-panel comparison plot: data, model, and residuals.

Generates a publication-quality figure showing the observed data, best-fit model, and residuals (data - model) side by side with appropriate colormaps and colorbars.

Parameters:
  • name (str, optional) – Output filename (with or without extension). Required for saving; if None, plot is saved with a default name.

  • component (None, str, int, list, or Profile, optional) –

    Model component(s) to include in the comparison. Can be:

    • None: Include all model components (default)

    • str: Single component name (e.g., ‘comp_00’)

    • int: Component index (e.g., 0 for the first component)

    • list: Multiple components as names, indices, or Profile objects

    • Profile: Object with id attribute specifying the component

    This is useful for comparing data against individual model components. Default is None (all components).

  • fmt (str, optional) – Output file format (e.g., ‘pdf’, ‘png’). Default is ‘pdf’.

  • fx (float, optional) – Figure width scaling factor. Default is 1.0.

  • fy (float, optional) – Figure height scaling factor. Default is 0.38.

  • dpi (float, optional) – Dots per inch for output resolution. Default is ~55.97.

  • cmaps (str, list, or dict, optional) –

    Colormap specification. Can be:

    • str: Single colormap applied to all panels

    • list: [data_cmap, model_cmap, residual_cmap]

    • dict: {‘data’: cmap, ‘model’: cmap, ‘residuals’: cmap}

    Defaults to [‘magma’, ‘magma’, ‘RdBu_r’].

  • cmap_data (str, optional) – Colormap for data panel (overrides cmaps). Default is ‘magma’.

  • cmap_model (str, optional) – Colormap for model panel (overrides cmaps). Default is ‘magma’.

  • cmap_residual (str, optional) – Colormap for residual panel (overrides cmaps). Default is ‘RdBu_r’.

  • gs_kwargs (dict, optional) – Keyword arguments for GridSpec layout (hspace, wspace, margins).

  • model_kwargs (dict, optional) – Keyword arguments passed to getmodel() for model generation. The ‘what’ argument is automatically set to ‘smoothed’ and ignored if provided.

Notes

  • Data and model panels share the same color scale

  • Residual panel uses a symmetric diverging colormap centered at 0

  • Uses APLpy for WCS-aware plotting

  • Automatically includes colorbars for data and residual panels

  • Output is saved at 300 DPI regardless of input dpi (used for sizing)

Examples

>>> # Standard comparison with all components
>>> fit.plot.comparison('comparison.pdf')
>>> # Compare data against a single component
>>> fit.plot.comparison('component_0.pdf', component=0)
autocorrelation(name=None, fmt='pdf', fx=0.5, fy=0.5, dpi=55.92321428571429, tau_factor=50, show_params=False)[source]

Plot autocorrelation time convergence diagnostic for emcee runs.

Creates a log-log plot showing how the integrated autocorrelation time estimates evolved during convergence-mode sampling. Useful for diagnosing whether the chain has converged.

Parameters:
  • name (str, optional) – Output filename (without extension). If None, displays plot interactively instead of saving. Default is None.

  • fmt (str, optional) – Output file format (e.g., ‘pdf’, ‘png’). Default is ‘pdf’.

  • fx (float, optional) – Figure width scaling factor. Default is 0.50.

  • fy (float, optional) – Figure height scaling factor. Default is 0.50.

  • dpi (float, optional) – Dots per inch for output resolution. Default is ~55.97.

  • tau_factor (float, optional) – Factor used for convergence criterion (chain length > tau_factor * tau). A dashed line at N/tau_factor is shown. Default is 50.

  • show_params (bool, optional) – If True, plot tau for each parameter individually. If False, only plot max(tau) across parameters. Default is False.

Raises:

ValueError – If tau_history is empty (run was not in convergence mode or tau never became reliable).

Notes

This plot is only available after running emcee with converge=True. The tau estimates become reliable when they cross below the dashed N/tau_factor line.