C-Plots: A unified plotting library for Cosmology.
Project description
A backend-agnostic cosmological plotting library.
Write your analysis once; render with matplotlib, plotly, or altair — no lock-in.
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
- Six plot types —
XYPlot,PKSpectrum,ClSpectrum,BackgroundEvolution,TrianglePlot,XYZColored - Three backends — publication PNG via matplotlib, interactive HTML via plotly, Vega-Lite JSON via altair
- 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
- Pluggable adapters — accepts NumPy arrays, pandas DataFrames, xarray Datasets, and GetDist
MCSamples - Zero lock-in — third-party backends and adapters register via
pyproject.tomlentry points
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")
Installation
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]"
Documentation
Full documentation, including the API reference, user guide, and interactive examples, is available at rcalderonb6.github.io/cplots.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cplots-0.0.1.tar.gz.
File metadata
- Download URL: cplots-0.0.1.tar.gz
- Upload date:
- Size: 25.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60f5a70f1e33e690b97795b48ddd7c43c4f5a746bfff65fda5b422ea7c4b3045
|
|
| MD5 |
348af76b0ba1ea95bab056124b683c2f
|
|
| BLAKE2b-256 |
70e84144daa15cc9a54c28f999b03af18d4f42bb04c8329dc92158b746fdabcc
|
File details
Details for the file cplots-0.0.1-py3-none-any.whl.
File metadata
- Download URL: cplots-0.0.1-py3-none-any.whl
- Upload date:
- Size: 41.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbe3f8ea79d15dec9cd9150ef5d25e5c7837dd6582914f204d64354d7df115ea
|
|
| MD5 |
f3a35fa65741007cfe162820318a0e22
|
|
| BLAKE2b-256 |
b30dcd223e95338102ab89ea8771f32603cb8d43a106895be42a9cf2dde3a299
|