corner.py

raw JSON →
2.2.3 verified Mon Apr 27 auth: no python

Corner.py makes beautiful corner plots (scatter plot matrices) for visualizing high-dimensional datasets, commonly used in Bayesian analysis (e.g., MCMC chains). Current version 2.2.3 requires Python >=3.9. Releases are infrequent, mainly maintenance.

pip install corner
error ImportError: cannot import name 'corner' from 'corner'
cause Attempting to import `corner` as a function instead of a module.
fix
Use import corner then call corner.corner(samples).
error ValueError: The number of truths (3) does not match the number of dimensions (2)
cause The `truths` list length differs from the number of columns in the samples array.
fix
Ensure truths has the same number of elements as samples.shape[1].
error TypeError: corner() got an unexpected keyword argument 'smooth'
cause Using deprecated `smooth` parameter in corner >=2.2.0.
fix
Use smooth1d and/or smooth2d instead.
error No module named 'arviz' when using 'corner'
cause ArviZ is an optional dependency; some workflows may unexpectedly require it.
fix
Install with pip install corner[arviz] or pip install arviz.
gotcha The `corner.corner()` function returns a matplotlib `Figure` object, not a `GridSpec` or an array of axes. Do not try to unpack the return value.
fix Capture the figure: `fig = corner.corner(...)` and use `fig.axes` to access subplots.
deprecated The `smooth` parameter for KDE smoothing is deprecated in favor of `smooth1d` and `smooth2d`.
fix Use `smooth1d=...` and/or `smooth2d=...` instead of `smooth=...`.
gotcha When passing `truths` (true parameter values), the list length must match the dimensionality of the samples (number of columns).
fix Ensure `truths` has the same number of elements as the columns of `samples`.
gotcha The `labels` parameter overrides the `quantiles` display on the histograms. If you want quantiles shown, ensure `labels` is not set or set it to include them.
fix Either omit `labels` or pass a list of label strings. Quantiles will appear if `show_titles=True` and `quantiles` is set.
gotcha Corner plots are memory-intensive for very large datasets (millions of points). Consider thinning your samples before plotting.
fix Subsample your data: `samples = samples[::10]`

Create a simple corner plot from random samples.

import corner
import numpy as np

# Generate random samples
ndim = 5
nsamples = 10000
np.random.seed(42)
samples = np.random.randn(ndim * nsamples).reshape([nsamples, ndim])

# Make the corner plot
figure = corner.corner(samples)

# Save to file
figure.savefig("corner_plot.pdf")