Repository navigation
Save plots as web figures for the docs theme - #97
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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'sPlotlyFigure(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.jsonis unchanged and still writes the figure as it is.save_figure's defaultplotly.jsonnow writes the web figure.result.to_json(web=True, **hints)returns the same text. Withoutweb=Trueit is unchanged, and hints raise aTypeError.plotly_backend.web_figure(fig, **hints)wrapsmaxplotlib.web.web_figure. Without maxplotlib it raises anImportErrorthat names the newwebextra (pip install "plasma-plots[web]").application/vnd.plotly.v1+jsonofdisplay_bundlecarries 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 extra asks for
maxplotlibx>=0.2, butmaxplotlib.webis 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.