Skip to content

Home

cplots wordmark

A backend-agnostic plotting library.

Write your analysis once; render using matplotlib, plotly, or altair with a single flag. No lock-in to any rendering engine.

Get started Browse the API

How it works

Every plot flows through three clean layers:

Raw arrays / DataFrames / xarray Datasets
    PlotData      immutable input containers
    PlotSpec      backend-agnostic IR — the decoupling boundary
    Backend       matplotlib · plotly · altair

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

  • Five plot types


    XYPlot  ·  PKSpectrum  ·  ClSpectrum  ·  BackgroundEvolution  ·  TrianglePlot  ·  XYZColored

    Plot types

  • Three backends


    Publication-quality PNG via matplotlib, interactive HTML via plotly, Vega-Lite JSON via altair.

    Backends

  • Multi-panel figures


    Compose plots into grids with colspan/rowspan, shared axes, and custom column/row ratios — two lines of code.

    Multi-panel figures

  • LaTeX labels


    Pass raw LaTeX strings through to plotly's MathJax renderer for publication-quality interactive HTML export.

    LaTeX labels


Quick example

import numpy as np
import cplots

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

cplots.PKSpectrum(k, pk, label="z=0").show()
# Interactive HTML — LaTeX rendered by MathJax
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")
fig = cplots.Figure.grid([
    [cplots.PKSpectrum(k, pk), cplots.BackgroundEvolution(z, {"H": Hz})],
    [cplots.XYPlot(x, y, labels=["theory", "data"])],
])
fig.show()

Install

pip install cplots[matplotlib]              # matplotlib only
pip install cplots[matplotlib,plotly]       # two backends
pip install cplots[all]                     # all backends + getdist

Development install

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