Metadata-Version: 2.3
Name: cplots
Version: 0.0.4
Summary: C-Plots: A unified plotting library for Cosmology.
Author: Rodrigo Calderon
Author-email: Rodrigo Calderon <calderon.cosmoly@gmail.com>
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: cplots[matplotlib,plotly,altair,getdist,pandas,polars] ; extra == 'all'
Requires-Dist: altair>=5.0 ; extra == 'altair'
Requires-Dist: pytest>=8.0 ; extra == 'dev'
Requires-Dist: mypy>=1.10 ; extra == 'dev'
Requires-Dist: ruff>=0.4 ; extra == 'dev'
Requires-Dist: mkdocs-material>=9.5 ; extra == 'docs'
Requires-Dist: mkdocstrings[python]>=0.25 ; extra == 'docs'
Requires-Dist: mkdocs-marimo>=0.2.1 ; extra == 'docs'
Requires-Dist: getdist>=1.4 ; extra == 'getdist'
Requires-Dist: matplotlib>=3.7 ; extra == 'matplotlib'
Requires-Dist: pandas>=1.5 ; extra == 'pandas'
Requires-Dist: plotly>=5.0 ; extra == 'plotly'
Requires-Dist: polars>=0.20 ; extra == 'polars'
Requires-Dist: ultraplot>=0.1 ; extra == 'ultraplot'
Requires-Python: >=3.10
Provides-Extra: all
Provides-Extra: altair
Provides-Extra: dev
Provides-Extra: docs
Provides-Extra: getdist
Provides-Extra: matplotlib
Provides-Extra: pandas
Provides-Extra: plotly
Provides-Extra: polars
Provides-Extra: ultraplot
Description-Content-Type: text/markdown

<p align="center">
  <img src="https://raw.githubusercontent.com/rcalderonb6/cplots/main/docs/assets/logo-wordmark.svg" width="65%" alt="cplots">
</p>

<p align="center">
  <strong>A backend-agnostic cosmological plotting library.</strong><br>
  Write your analysis once; render with <code>matplotlib</code>, <code>plotly</code>, or <code>altair</code> — no lock-in.
</p>

<p align="center">
  <a href="https://pypi.org/project/cplots/"><img src="https://img.shields.io/pypi/v/cplots.svg?color=blue" alt="PyPI version"></a>
  <a href="https://pypi.org/project/cplots/"><img src="https://img.shields.io/pypi/pyversions/cplots.svg" alt="Python versions"></a>
  <a href="https://rcalderonb6.github.io/cplots/"><img src="https://img.shields.io/badge/docs-rcalderonb6.github.io%2Fcplots-blue" alt="Docs"></a>
  <a href="https://github.com/rcalderonb6/cplots/actions/workflows/docs.yml"><img src="https://github.com/rcalderonb6/cplots/actions/workflows/docs.yml/badge.svg" alt="Deploy docs"></a>
</p>

---

## 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.toml` entry points

---

## Quick example

```python
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

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

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

# Global default
cplots.set_backend("plotly")
```

---

## Installation

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

**Development install:**

```bash
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](https://rcalderonb6.github.io/cplots/).
