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:

Arrays · DataFrames · xarray · GetDist      Solver results (CLASS, CAMB, eft4py)
               │                                      │ as_observables
               │                              Observables   one vocabulary, with units
               └──────────────→ PlotData ←────────────┘     immutable input containers
                                   ↓
                                PlotSpec                    backend-agnostic IR
                                   ↓
                 Backend   matplotlib · plotly · altair · ultraplot

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 plots into grids with colspan/rowspan, shared axes, and custom ratios
  • LaTeX labels — pass raw LaTeX strings through to plotly's MathJax renderer
  • 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, label="z=0").show()

# Interactive HTML with LaTeX labels
cplots.PKSpectrum(
    k, pk,
    x_label=r"$k\;[h\,\mathrm{Mpc}^{-1}]$",
    y_label=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 (Python ≥ 3.12; from source until a release ships BackgroundGrid.to_hiclass()).

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.5

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.5
File Size Uploaded Provenance Actions
cplots-0.0.5.tar.gz 115.9 kB With provenance Details for cplots-0.0.5.tar.gz

Built distribution (wheel)

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

Total release size: 265.2 kB

Release files / cplots-0.0.5.tar.gz

Download URL cplots-0.0.5.tar.gz
Size 115.9 kB
Tags Source
SHA-256 checksum
How to use checksums
783dd8aae6fd6207c52bb9a8a53d153613318ec82b584be1da06172427bbc7cd
BLAKE2b-256 checksum
How to use checksums
eadafb0c9960909fc1886f7455fdd245e18aa3ad1a2fb6324afe56e0c80e058a
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 12, 2026.

Transparency log

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

Download URL cplots-0.0.5-py3-none-any.whl
Size 149.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
077d290174bb75e37b3a1eff60f441dbefb4b115cda82ff668326a4b08f75baa
BLAKE2b-256 checksum
How to use checksums
bb49081e38f53f0f9e945b177e23e0db76d92eec2978d39c34414760b6080b9c
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 12, 2026.

Transparency log

Security for cplots 0.0.5

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.5.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 12, 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