Plot Types¶
cplots ships five plot types, each backed by a dedicated data container.
XYPlot¶
Generic x/y line plot. Accepts one or many traces.
Multiple traces with a shared x axis:
PKSpectrum¶
Matter power spectrum P(k). Log-log axes. Raw arrays get the unit-free labels $k$ and $P(k)$; spectra from the CLASS/CAMB adapters carry labels with units.
Multiple redshifts on the same axes:
Secondary multipole axis¶
Pass secondary_x_axis=cplots.multipole_axis(chi=...) to show the corresponding CMB
multipole ℓ ≈ k · χ on the top x-axis. chi is the comoving distance in the same
units as k (typically Mpc/h):
Any 2D plot can get a secondary axis through .axes(): secondary_x= adds a top
x-axis and secondary_y= a right y-axis, each a cplots.SecondaryAxisSpec with
forward/inverse maps and a label. The primary axes' mirrored ticks on that side
are hidden so they don't overlap the secondary ticks. Secondary axes are drawn by
matplotlib; other backends warn and skip them.
E = cplots.SecondaryAxisSpec(forward=lambda h: h / 67.4, inverse=lambda e: e * 67.4,
label=r"$E(z)$")
cplots.XYPlot(z, Hz, ylabel=r"$H(z)$ [km/s/Mpc]").axes(secondary_y=E).render()
PrimordialSpectrum¶
Primordial power spectrum, log-log, with the label $P_s(k)$ against
$k\;[\mathrm{Mpc}^{-1}]$. It takes arrays, or the PKData returned by the
CLASS/CAMB adapters' primordial().
ClSpectrum¶
CMB angular power spectrum C_ell. Linear x, log y.
Secondary wavenumber axis¶
Pass secondary_x_axis=cplots.wavenumber_axis(chi=...) to show the corresponding
wavenumber k ≈ ℓ / χ on the top x-axis:
BackgroundEvolution¶
Cosmological background quantities against redshift.
It also takes solver outputs directly (Solver Adapters), and a
{label: source} mapping overlays several codes or models: one line style per source,
one colour per quantity, units converted to the first source's. Here two analytic
models, one of them with H in km/s/Mpc:
BackgroundPanels gives each kind of quantity its own panel:
TrianglePlot¶
MCMC posterior corner plot of one chain, or of several overlaid chains passed as a
list or a {label: chain} dict (see Triangle engines).
PosteriorBands¶
Credible bands of an observable y(z) from posterior samples (one row per
sample), with the median and optional data points. levels sets the
confidence levels (default 1σ and 2σ); weights takes importance weights.
All bands and the median share one colour, the first palette colour unless you
pass color=; the data points use the second palette colour, or data_color=.
To compare several sample sets on one grid, pass BandGroups to
PosteriorBandsGroup; it also takes reference curves, horizontal lines, points
and text annotations. See the API reference.
XYZColored¶
XY plot where each curve is color-coded by a scalar Z value — useful for parameter sweeps.
XYZColoredGrid¶
Grid of XYZColored panels sharing a common Z axis. Use shared_colorbar=True
to normalise all panels to the same color scale and draw a single colorbar.
Single shared colorbar:
Auto-layout computes ncols = ceil(sqrt(N)) when nrows/ncols are not given.
Override with explicit nrows and ncols for full control.
PhasePortrait¶
Streamlines of a 2D or 3D vector field, coloured by speed or arclength, with
optional fixed points (fixed_points="auto" finds and classifies them),
nullclines and arrows. axis_labels, clabel, clim and colorbar= control
the labels and colour scale. Needs the dynamics extra (SciPy). See the
phase portraits example for a full walkthrough.
Residuals¶
Any plot can produce a residual view via two methods on the plot object:
plot.residuals()— returns a newXYPlotwith residual traces.plot.with_residuals()— returns aResidualFigurewith two stacked panels sharing an x-axis.
Standalone residuals¶
mode="relative" gives (y − y_ref) / y_ref — the most common choice for comparing
models where the absolute scale varies.
mode="absolute" is useful when you care about the raw difference in the same
units as the original y-axis.
Two-panel stacked figure¶
with_residuals() stacks the main plot and its residuals into a single figure
with a shared x-axis. The heights argument controls panel proportions.