Skip to content

cornetto

Tests Coverage License: MIT PyPI Built with Claude

Fast, smooth corner plots for MCMC chains.

Early release

cornetto is built for research use and works well for everyday analysis, but the API may still evolve and some features are still maturing. Feedback and contributions are very welcome — open an issue or a PR.

Cornetto is a Python library for visualising Bayesian posterior samples — the kind you get out of samplers like bilby, emcee, or dynesty. Feed it a plain dict of sample arrays and it returns a (fig, axes) pair you can save or embed in a notebook.

The speed comes from KDExpress, a JAX-based FFT-KDE library that computes smooth 1-D and 2-D densities in O(N log N) time. At 20k samples a full corner plot renders in well under a second on CPU; quick_corner (histograms only) is faster still.

cornetto corner plot

Install

pip install cornetto

Quick example

import numpy as np
from cornetto import corner

data = {
    "mass_1": chain["mass_1"],    # 1-D array of posterior samples
    "mass_2": chain["mass_2"],
    "chi_eff": chain["chi_eff"],
}

fig, axes = corner(
    data,
    labels={"mass_1": r"$m_1\,[M_\odot]$",
            "mass_2": r"$m_2\,[M_\odot]$",
            "chi_eff": r"$\chi_{\mathrm{eff}}$"},
    truths={"mass_1": 35.6},
    chain_labels=["GW200129"],
)
fig.savefig("posterior.pdf", bbox_inches="tight")

For fast iteration during analysis, skip the KDE entirely:

from cornetto import quick_corner
fig, axes = quick_corner(data)   # histograms only, sub-second

What you get

Feature Detail
FFT-KDE contours JAX-accelerated, O(N log N). Smooth at 10k–100k samples.
quick_corner Histogram-only path, ~7× faster. Same dict API.
Multi-chain Pass (N_chains, N_samples) arrays. Palette and legend are automatic.
Sparse chains Parameters can be absent for some chains - pass a shorter array or None.
Summary tables c.summary() renders HTML in Jupyter; c.latex() produces AASTeX output.
Reproducible style Plots look identical regardless of prior rcParams changes in the notebook.

Where to go next