Metadata-Version: 2.4
Name: proteus-mpl
Version: 1.5.0
Summary: PROTEUS Thermocline matplotlib theme: brand color cycles, phase colormaps, light + dark variants.
Author-email: PROTEUS collaboration <dev@proteus-framework.org>
License: Apache-2.0
Project-URL: Homepage, https://formingworlds.github.io/proteus-visual-language
Project-URL: Repository, https://github.com/FormingWorlds/proteus-visual-language
Project-URL: Changelog, https://github.com/FormingWorlds/proteus-visual-language/blob/main/CHANGELOG.md
Keywords: matplotlib,style,theme,PROTEUS,planetary-science
Classifier: Framework :: Matplotlib
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Visualization
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: matplotlib>=3.8
Provides-Extra: validation
Requires-Dist: pillow>=11.3; extra == "validation"
Provides-Extra: test
Requires-Dist: pytest>=7.0; extra == "test"
Requires-Dist: pillow>=11.3; extra == "test"
Requires-Dist: hypothesis; extra == "test"
Dynamic: license-file

# proteus-mpl

PROTEUS Thermocline matplotlib theme. Publication-grade figures whose colors,
fonts, and surfaces match the slides, the website, and the docs.

## Install

```bash
pip install proteus-mpl
```

From a checkout of the repository: `pip install figures/proteus-mpl` (or cd
into the folder and `pip install .`).

The package needs Python 3.9 and matplotlib 3.8 or newer; CI runs the tests on the newest matplotlib and on matplotlib 3.8.0 with Python 3.9 and 3.11. The pytest plugin needs pytest 7 or newer.

## Use

```python
import proteus_mpl
proteus_mpl.use()           # light: Paper background — papers, light slides
# proteus_mpl.use("dark")   # dark: Void background — dark slides, hero figures
# proteus_mpl.use("white")  # light theme on pure white — journal pages
```

## What you get

- **Cycles** — both neutral-first, so a single-series plot draws in ink
  (light) / paper (dark) and magma stays a deliberate signal. Light
  (`proteus_mpl.CYCLE`, 9 colours): ink, magma, solar, verdant, ocean, tidal,
  outgassing, fog, azure; CVD worst-pair ΔE 15.7 (Machado 2009). Dark
  (`CYCLE_DARK`, 6 colours): paper, magma, solar, and light-safe tones; ΔE
  16.8. Past the cycle, switch line style (solid/dashed/dotted/dash-dot)
  instead of adding hues, and keep legends on multi-series plots.
- **Accents** — `COLORS["solar"]` (`#E0A32E`, the star) with
  `COLORS["solar_deep"]` (`#C8860F`) for gold fills or thin marks on light
  surfaces, and `COLORS["verdant"]` (`#57A05C`, the habitable endpoint).
- **Module domain colors** — `proteus_mpl.DOMAINS["interior"]` etc, seven of
  them. Use these whenever a line *is* a module (SPIDER output → interior red,
  MORS → solar gold, Morrigan → accretion clay `#A38F7A`). Stable across every
  paper, talk, and diagram. Three of them are light in tone and thin out on a
  pale page: stellar gold at 2.0:1, atmosphere blue at 2.5:1, and accretion clay
  at 2.8:1 against Paper. Give those a legend rather than leaning on the hue for
  small marks.
- **Colormaps** — `proteus` (sequential, Void→Paper; default for imshow /
  pcolormesh; the one ramp that survives greyscale reproduction),
  `proteus_div` (diverging, light midpoint — print-safe for
  anomalies/residuals), `proteus_phase` (the brand ramp, magma→void→ocean,
  dark midpoint — hero figures and dark slides). `_r` reversals registered.
- **Type** — Instrument Sans labels, Spline Sans Mono available for ticks via
  `fontfamily="Spline Sans Mono"`; titles bold, left-aligned. The OFL brand
  fonts ship inside the package and register automatically on `use()`.
- **Publication settings** — 300 dpi savefig, tight bbox, TrueType embedding
  (fonttype 42), text-as-paths SVG. Prefer `fig.savefig("fig.pdf")`.

## The cycle on each surface

![light cycle](examples/cycle_light.png)
![dark cycle](examples/cycle_dark.png)

Regenerate with `python examples/cycle.py`.

## Validation plots

`proteus_mpl.validation.save` writes one validation plot as a light and a dark file. With the same matplotlib and Pillow versions the same figure gives the same bytes, so the files can be committed next to the docs:

```python
from proteus_mpl.validation import save

def make_figure():
    fig, ax = plt.subplots()
    ax.plot(t, model, label="model")
    ax.plot(t_ref, ref, "o", label="reference")
    return fig

save(make_figure, "melt_fraction", "docs/assets/validation")              # melt_fraction.svg, melt_fraction_dark.svg
save(make_heatmap, "phase_map", "docs/assets/validation", kind="map")     # phase_map.avif, phase_map_dark.avif
```

`make_figure` is called once per theme, so it must create the figure itself. Line and point plots (`kind="line"`) are SVG with text as paths, no date, a fixed creator and a fixed hash salt; maps and heatmaps (`kind="map"`) are AVIF at quality 80 with fixed encoder settings and need Pillow with AVIF support (`pip install "proteus-mpl[validation]"`). A file above 60 000 B (`validation.MAX_BYTES`) is refused with its name and size, and nothing is written; a dense field belongs in `kind="map"`, while a small element drawn with `rasterized=True` can stay in an SVG as long as the file is under the cap. A name must not end in `_dark`, the suffix of the dark file. The test id and the command that makes the plot again go into the file metadata.

The package registers a pytest plugin, `proteus_mpl.pytest_plugin`, which needs pytest 7 or newer and loads by itself; a conftest does not need to list it. A test asks for the `validation_plot` fixture and calls it with the factory and a name:

```python
@pytest.mark.reference_pinned
def test_melt_fraction(validation_plot):
    t, model = run_case()
    assert np.allclose(model, ref, rtol=1e-3)
    validation_plot(lambda: plot_case(t, model), "melt_fraction")
```

Without the option the fixture checks the plot against the committed pair:

- It calls the factory, renders both themes in memory, applies the size cap and writes nothing, so each run of the test pays for two renders (a smooth 200 x 200 map takes about 0.6 s on an arm64 Mac, most of it in rasterizing and encoding the two files).
- It compares a data summary of the figure with the summary stored in both committed files in `docs/assets/validation`. The summary holds, per axes, inset axes and parasite axes, the axis scales, the category names of categorical axes, and the point count and the min, max, mean and a ramp-weighted mean of each coordinate of every line, every collection (offsets of scatter points, hexbins, quivers and barbs, mesh coordinates, vertices of fills, error bars and contours; labelled line contours from their contour generator, so label gaps, figure size, font size and dpi do not count; a labelled contour set without one, such as one built from segments, is read from its drawn paths, where inline label gaps count) and its colour values (in log10 under a log norm, and the norm scale of each is kept; and the vectors of quivers and barbs, masks kept), the corners of all patches except annotation arrows (bars, histograms, `ax.arrow`), and every image with its origin and extent.
- Coordinates are in axis units; on a log axis the statistics are of the log10 of the values (values at or below zero are left out), and symlog and logit axes stay linear. The ramp weight runs from -1 at the first point to 1 at the last, so a reversed series is found, and the order of scatter points and bars counts; a change inside a series that leaves all four statistics within the tolerance is not found.
- A value passes within `validation.SUMMARY_RTOL` (1e-6) of the range of the committed coordinate, or of a tenth of its largest magnitude when that is larger (on a log axis and under a log norm, of the range of the log10 values or 0.1 decade when that is larger, so the tolerance is at least 1e-7 decade at any magnitude: 1 and 1 + 1e-12 agree, 1 and 1 + 1e-5, 4.3e-6 decade apart, differ); counts, axis and norm scales and category names must match. Large offsets set the floor: on a date axis near 2024 it is about 170 s. A coordinate that is round-off noise, such as a residual near 1e-16, differs between machines on its own scale; plot it with a floor well above the noise, such as `np.maximum(residual, 1e-12)` for a residual near 1e-16 on a log axis, or leave it out.
- Not compared: 3D and secondary axes, the base of a log scale, axis labels, limits, text, colours, artist transforms, annotation arrows, the shapes of offset markers and the interior cell edges of `pcolorfast` and `NonUniformImage` images; a colorbar is compared as an axes, so a colormap with another number of colours changes it.
- Which artists a plot type makes depends on the matplotlib version, so make the pairs with the matplotlib the repository's CI installs, and make them again after an upgrade. The summary adds about 90 to 170 B per line and 90 B per axes to each file, which counts toward the size cap.
- A factory whose light and dark figures hold different data is refused. A missing committed file, a file committed under a name that differs only in case (the message asks for a `git mv`), a file that is not a whole SVG or AVIF (empty, cut, an LFS pointer), an unreadable summary or a summary that differs fails the test with a hint to make the pair again. A committed file without a summary of the current format passes with a warning, which fails the test in a repository that sets `filterwarnings = error`.
- A test that takes `validation_plot` and passes without calling it fails at teardown.

With the option the fixture writes and does not compare; on a case-insensitive file system it renames a committed file whose name differs only in case. `pytest -m reference_pinned --validation-plots` writes every plot to `docs/assets/validation` under the pytest rootdir; `--validation-plots=DIR` writes to another folder, relative to the rootdir. A bare `--validation-plots` followed by a word, which it would read as its folder, is refused, also from `addopts` or an `@argfile`, so write `--validation-plots=DIR` (always in `addopts` and `PYTEST_ADDOPTS`) or put the option after the test paths. A plot name used twice for one kind in a session is refused, with or without the option, so a parametrized test needs one name per parameter, such as `f"case_{param}"`; a rerun of the same test may use its names again. The `reference_pinned` marker belongs to the repository that runs the tests, which registers it in its pytest configuration. Under pytest-xdist each worker keeps its own list of names, so a name repeated in tests that run on different workers is not caught. The stamped command names a folder given with `--validation-plots=DIR`.

## Conventions

- Size figures at final printed size (A&A column ≈ 3.5 in) and keep default
  font sizes — never shrink a huge figure down.
- Light figures on light surfaces, dark figures on dark — no visible card.
- Journal white pages: `use("white")`, or `transparent=True` at savefig.
- Magma is the *hot signal*: reserve it for the series you want the room to
  look at. Everything else starts from Ocean.
