Skip to main content

C-Plots: A unified plotting library for Cosmology.

Project description

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 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 typesXYPlot, 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.toml entry 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cplots-0.0.4.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cplots-0.0.4-py3-none-any.whl (41.1 kB view details)

Uploaded Python 3

File details

Details for the file cplots-0.0.4.tar.gz.

File metadata

  • Download URL: cplots-0.0.4.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cplots-0.0.4.tar.gz
Algorithm Hash digest
SHA256 53ed4a2983eeccac50a5657f78eb3cf568c4737a0e347312bc1b620b1b520801
MD5 6812eb775d44f77e167ec44a5281a36d
BLAKE2b-256 d7a9bd313264d97590f5db2c57ea632feb05d2431bf41db052d9e762933c35f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for cplots-0.0.4.tar.gz:

Publisher: pypi.yml on rcalderonb6/cplots

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cplots-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: cplots-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 41.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cplots-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d2c7e0ecb3db0ceb4ec3431d974b3e291bc66bc8667833f14ec228e89fd52179
MD5 b4fee5731b50695509e015d11d24bc26
BLAKE2b-256 5c31c287ec51bb7c1ab4c1bcf2a9a19c57ac1e22c61378ac20eba11e2efe6602

See more details on using hashes here.

Provenance

The following attestation bundles were made for cplots-0.0.4-py3-none-any.whl:

Publisher: pypi.yml on rcalderonb6/cplots

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page