Skip to content

Save plots as web figures for the docs theme - #97

Merged
max-models merged 1 commit into
develfrom
web-figures
Nov 7, 2026
Merged

max-models merged 1 commit into
develfrom
web-figures

Conversation

@max-models

@max-models max-models commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

A plot can now be saved as a web figure, the format of maxplotlib.web (max-models/maxplotlib#85). The file holds Plotly JSON without plotly.js and without a look of its own. The docs theme's PlotlyFigure (max-models/starlight-theme#53) embeds it in the site's light and dark colours.

  • result.save("x.plotly.json", alt=..., title=..., aspect=..., white_plot=...) writes a web figure. A Matplotlib result is converted to Plotly first, and animations keep their frames and slider. A plain .json is unchanged and still writes the figure as it is. save_figure's default plotly.json now writes the web figure.
  • result.to_json(web=True, **hints) returns the same text. Without web=True it is unchanged, and hints raise a TypeError.
  • plotly_backend.web_figure(fig, **hints) wraps maxplotlib.web.web_figure. Without maxplotlib it raises an ImportError that names the new web extra (pip install "plasma-plots[web]").
  • Notebook output: with maxplotlib installed, the application/vnd.plotly.v1+json of display_bundle carries the palette slots and the title hint of a web figure. A docs site built from the notebook then recolours it like a saved .plotly.json. The output keeps its own template, size and backgrounds for Jupyter, and without maxplotlib it is the plain JSON as before.
  • The Plotly guide describes the new format, and API.md is regenerated.

The extra asks for maxplotlibx>=0.2, but maxplotlib.web is only on maxplotlib devel, so the floor needs bumping to the release that ships it before plasma-plots is released. On main the new tests skip until then.

Checks: 7 new tests in tests/test_web_figures.py. Locally 1027 tests pass and 15 are skipped. One vtk.js scene test is deselected because this local environment has no trame (it fails without this change too). The pre-commit hooks pass.

@max-models
max-models merged commit 1b7a36b into devel Nov 7, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant