Skip to main content

cplots

A backend-agnostic cosmological plotting library.
Write your analysis once; render with matplotlib, plotly, or altair — no lock-in.

PyPI version Python versions Docs Deploy docs


How it works

Every plot flows through the same layers, whether it starts from arrays or from a Boltzmann/dark-energy solver:

flowchart TD
    raw["Arrays · DataFrames · xarray · GetDist"]
    solver["Solver results<br/>CLASS · CAMB · eft4py"]
    obs["<b>Observables</b><br/>one vocabulary, with units"]
    data["<b>PlotData</b><br/>immutable input containers"]
    spec["<b>PlotSpec</b><br/>backend-agnostic IR"]
    backend["<b>Backend</b><br/>matplotlib · plotly · altair · ultraplot"]

    solver -- as_observables --> obs
    raw -- to_plot_data --> data
    obs --> data
    data -- "Plot.spec()" --> spec
    spec -- "render · show · save" --> backend

Plot subclasses never import backends. Backends never import plot subclasses. Swap the backend at call time, via a context manager, or globally — the plot code stays unchanged.


Features

  • Plot types
    • general: XYPlot, XYZColored, XYZColoredGrid, PhasePortrait
    • cosmology: PKSpectrum, ClSpectrum, PrimordialSpectrum, BackgroundEvolution, BackgroundPanels, ThermodynamicsEvolution
    • inference: TrianglePlot (getdist, chainconsumer or anesthetic engines), PosteriorBands
    • residual panels: ResidualFigure, plot.with_residuals(...)
  • Four backends — publication figures via matplotlib or ultraplot, interactive HTML via plotly, Vega-Lite JSON via altair (multi-panel figures: matplotlib, plotly, altair)
  • Solver adapters — CLASS / hi_class, CAMB and eft4py outputs through one interface: shared quantity names (H, dA, w_de, alpha_M, …), units tracked and converted, any redshift grid via z=
  • Code comparisons — overlay several codes with {label: source}; units are matched automatically, and BackgroundPanels gives each kind of quantity its own panel
  • Multi-panel figures: compose with (a | b) / c or an explicit grid with colspan/rowspan, shared axes and custom ratios (full support on matplotlib and plotly; altair has no rowspan or shared axes)
  • Formatting and styles: chainable, immutable formatting (plot.axes(xlim=...).legend(...)) and a Style cascade (global, then with cplots.style(...), then figure, then plot) applied per render. Every plot starts from cplots.DEFAULT: Computer Modern text and math, FiveThirtyEight colours, boxed axes with inward ticks, magma colormaps
  • LaTeX labels — labels (including the defaults, e.g. $P(k)$) render as math in matplotlib; plotly gets Unicode, or MathJax with latex_labels=True
  • Command line — cplots distributions triangle CHAIN and cplots lines xy FILE (pip install "cplots[cli]")
  • Data adapters — NumPy arrays, pandas / polars DataFrames, xarray Datasets, GetDist MCSamples
  • Extensible, light imports — backends register via the cplots.backends entry point; data and solver adapters with @cplots.to_plot_data.register / @cplots.as_observables.register (a solver adapter subclasses Observables and implements one hook). Optional libraries are only imported when used.

Quick example

import numpy as np
import cplots

k  = np.logspace(-3, 0, 200)
pk = k ** -1.5

# Display with default backend (matplotlib)
cplots.PKSpectrum(k, pk, labels="z=0").show()

# Interactive HTML with LaTeX labels
cplots.PKSpectrum(
    k, pk,
    xlabel=r"$k\;[h\,\mathrm{Mpc}^{-1}]$",
    ylabel=r"$P(k)\;[h^{-3}\,\mathrm{Mpc}^3]$",
    latex_labels=True,
).save("pk.html", backend="plotly")

# Multi-panel figure
z  = np.linspace(0, 3)
Hz = 67.34 * np.sqrt(0.3 * (1 + z)**3 + 0.7)

fig = cplots.Figure.grid([
    [cplots.PKSpectrum(k, pk), cplots.BackgroundEvolution(z, {"H": Hz})],
])
fig.show()

Switching backends

# Per call
plot.show(backend="plotly")

# Context manager
with cplots.backend("altair"):
    plot.show()

# Global default
cplots.set_backend("plotly")

Cosmology solvers

Hand cplots a computed solver result; as_observables picks the adapter, and every code answers the same background() call in the same vocabulary:

out = cplots.as_observables(cosmo)          # classy.Class -> ClassOutput
bg = out.background(quantities=["H", "dA"], units={"H": "km/s/Mpc"}, z=np.linspace(0, 3, 100))

# Overlay codes: one line style per source, CAMB's km/s/Mpc and CLASS's 1/Mpc matched for you
cplots.BackgroundPanels(
    {"hi_class": cosmo, "eft4py": grid, "CAMB": camb_results},
    ["H", "dA"],
    units={"H": "km/s/Mpc"},
).show()

# Dark-energy quantities, from hi_class and an eft4py BackgroundGrid
cplots.BackgroundEvolution({"hi_class": cosmo, "eft4py": grid}, ["w_de"]).show()

P(k), Cℓ, primordial and thermodynamics outputs are available where a code provides them (out.pk(), out.cl(), …). See the Solver Adapters guide and the eft4py notebook.


Installation

pip install cplots[matplotlib]              # matplotlib only
pip install cplots[matplotlib,plotly]       # two backends
pip install cplots[all]                     # matplotlib, plotly, altair, pandas, polars, triangle engines, scipy
pip install cplots[ultraplot]               # ultraplot backend (not included in [all])
pip install cplots[camb]                    # CAMB adapter
pip install cplots[classy]                  # CLASS adapter (builds classy)
pip install cplots[cosmo]                   # both solvers (not included in [all])
pip install cplots[dynamics]                # scipy integrators for PhasePortrait

eft4py is not an extra: install it separately (pip install "eft4py>=0.0.6", Python ≥ 3.11).

Development install:

git clone https://github.com/rcalderonb6/cplots
pip install -e ".[matplotlib,dev]"

Documentation

Full documentation, including the API reference, user guide, and interactive examples, is available at rcalderonb6.github.io/cplots:

Metadata

Release files for cplots 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cplots 0.0.6
File Size Uploaded Provenance Actions
cplots-0.0.6.tar.gz 144.6 kB With provenance Details for cplots-0.0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cplots 0.0.6
File Interpreter ABI Platform Actions
cplots-0.0.6-py3-none-any.whl Python 3 none any Details for cplots-0.0.6-py3-none-any.whl

Total release size: 324.5 kB

Release files / cplots-0.0.6.tar.gz

Download URL cplots-0.0.6.tar.gz
Size 144.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c2c2bd3cc19d17cd24e61ac264660c7d75b9a5ae0a365300c3f2040c28bec34c
BLAKE2b-256 checksum
How to use checksums
00a801500bedd86a75e784b4a6ccddd9c850966a31180d51a2360f89f2132e79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

Release files / cplots-0.0.6-py3-none-any.whl

Download URL cplots-0.0.6-py3-none-any.whl
Size 179.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aed342ccc9c5ec080bec082add4dac463bfb186e1170d808c24bbb77faf934ee
BLAKE2b-256 checksum
How to use checksums
0a92f075ee756a8591f78b45173fbc7ac37a13a598c28d8db2245e116e5de98d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

Security for cplots 0.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cplots-0.0.6.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page