Skip to content

Web figures: theme-neutral Plotly JSON for the docs sites - #85

Merged
max-models merged 2 commits into
develfrom
web-figures
Nov 7, 2026
Merged

max-models merged 2 commits into
develfrom
web-figures

Conversation

@max-models

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

Copy link
Copy Markdown
Owner

Adds a file format for interactive figures on the max-models docs sites, and the writer for it, so a figure is saved once and embedded on any page without plotly.js in the file.

maxplotlib.web

  • web_figure(fig, title=, alt=, aspect=, white_plot=) turns any Plotly figure (or its JSON as a dict) into the format; write_web_figure(fig, path, ...) writes it.
  • The format is Plotly JSON (data, layout, frames) with no look of its own: no template, no fixed size, and transparent backgrounds. The axes get automargin so the tick labels fit at any size.
  • Data palette: a trace whose colour comes from a default cycle (Matplotlib C0–C9, Plotly's colorway, Okabe–Ito) gets trace.meta.color_slot. The page can then give it the theme's colour in that position. Traces without a colour follow layout.colorway, black traces take the text colour, and other explicit colours and colormaps stay.
  • Hints in layout.meta.web: version, title, alt, aspect, white_plot (on by default for figures converted from Matplotlib).

Canvas

  • canvas.to_json(title=, alt=, white_plot=) returns the web figure; canvas.savefig("x.plotly.json", backend="plotly") writes it. The aspect ratio comes from the canvas size.

Docs

Checks

  • 9 new tests; all 340 tests pass. The pre-commit hooks pass, and the site builds with the link check.
  • Checked in the theme's example site: a saved canvas takes the palette in light and dark mode.

@max-models
max-models merged commit e073efa into devel Nov 7, 2026
49 of 55 checks passed
@max-models
max-models deleted the web-figures branch November 7, 2026 11:15
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