Skip to content

Note

Click here to download the full example code

Marginal Distributions

marginal() shows each parameter's 1-D KDE in a tidy grid, with optional CI bands and truth markers. No 2-D panels — ideal for quick parameter summaries or chains with many parameters.

Shared synthetic posterior

import numpy as np
from cornetto import marginal

rng = np.random.default_rng(0)
N = 20_000

data = {
    "mass_1": rng.normal(30, 4, N),
    "mass_2": rng.normal(25, 3, N),
    "spin":   rng.uniform(-1, 1, N),
    "dist":   rng.exponential(400, N),
}

labels = {
    "mass_1": r"$m_1\,[M_\odot]$",
    "mass_2": r"$m_2\,[M_\odot]$",
    "spin":   r"$\chi_{\mathrm{eff}}$",
    "dist":   r"$d_L\,[\mathrm{Mpc}]$",
}

Default marginal grid

Four panels arranged in one row, with value⁺ᵃ₋ᵦ titles and a truth marker on mass_1.

fig, axes = marginal(
    data,
    labels=labels,
    truths={"mass_1": 30.0},
    chain_labels=["GW200129"],
    ncols=4,
)

$m_1\,[M_\odot]$ = $30.0^{+4.0}_{-3.9}$, $m_2\,[M_\odot]$ = $25.0^{+3.0}_{-3.0}$, $\chi_{\mathrm{eff}}$ = $-0.01^{+0.69}_{-0.68}$, $d_L\,[\mathrm{Mpc}]$ = $272^{+461}_{-202}$

Multi-chain marginals

Compare two events side-by-side. The legend appears automatically when n_chains >= 2.

data_2 = {
    k: np.stack([data[k], rng.normal(data[k].mean() + 5, 3, N)])
    for k in ["mass_1", "mass_2"]
}

fig, axes = marginal(
    data_2,
    labels={k: labels[k] for k in ["mass_1", "mass_2"]},
    chain_labels=["Event A", "Event B"],
    ncols=2,
)

plot 1 marginal

Filled curves, coral color

fill_1d=True adds a light tint under each KDE curve.

fig, axes = marginal(
    data,
    labels=labels,
    chain_labels=["GW200129"],
    ncols=4,
    fill_1d=True,
    color="coral",
)

$m_1\,[M_\odot]$ = $30.0^{+4.0}_{-3.9}$, $m_2\,[M_\odot]$ = $25.0^{+3.0}_{-3.0}$, $\chi_{\mathrm{eff}}$ = $-0.01^{+0.69}_{-0.68}$, $d_L\,[\mathrm{Mpc}]$ = $272^{+461}_{-202}$

HDI statistic

Switch the CI interval to the 68 % Highest Density Interval instead of the default 16–84 percentile band.

fig, axes = marginal(
    data,
    labels=labels,
    chain_labels=["GW200129"],
    ncols=4,
    stat="median_hdi",
)

$m_1\,[M_\odot]$ = $30.0^{+4.2}_{-3.7}$, $m_2\,[M_\odot]$ = $25.0^{+2.9}_{-3.1}$, $\chi_{\mathrm{eff}}$ = $-0.01^{+0.45}_{-0.90}$, $d_L\,[\mathrm{Mpc}]$ = $272^{+179}_{-272}$

Total running time of the script: ( 0 minutes 1.791 seconds)

Download Python source code: plot_1_marginal.py

Download Jupyter notebook: plot_1_marginal.ipynb

Gallery generated by mkdocs-gallery