-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DX: support Plotly in static webpages (#208)
* DOC: add `plotly` with `ipywidgets example to TR-006 * DOC: add `plotly` example notebook TR-023 * DX: import JS files through `html_js_files` * FIX: update `ipywidgets` Using `ipywidgets` <v8 causes Javascript error
- Loading branch information
Showing
6 changed files
with
270 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"hideCode": true, | ||
"hideOutput": true, | ||
"hidePrompt": true, | ||
"jupyter": { | ||
"source_hidden": true | ||
}, | ||
"slideshow": { | ||
"slide_type": "skip" | ||
}, | ||
"tags": [ | ||
"remove-cell" | ||
] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%config InlineBackend.figure_formats = ['svg']\n", | ||
"import os\n", | ||
"\n", | ||
"STATIC_WEB_PAGE = {\"EXECUTE_NB\", \"READTHEDOCS\"}.intersection(os.environ)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"```{autolink-concat}\n", | ||
"```" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"tags": [ | ||
"documentation", | ||
"jupyter", | ||
"sphinx", | ||
"3d" | ||
] | ||
}, | ||
"source": [ | ||
"::::{margin}\n", | ||
":::{card} Support for Plotly plots in Technical Reports\n", | ||
"TR-023\n", | ||
"^^^\n", | ||
"+++\n", | ||
"✅ [compwa-org#206](https://github.com/ComPWA/compwa-org/issues/206)\n", | ||
":::\n", | ||
"::::" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"# 3D plots with Plotly\n", | ||
"<!-- cspell:ignore isomax isomin isosurface mgrid -->" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"tags": [ | ||
"remove-cell" | ||
] | ||
}, | ||
"source": [ | ||
"<!-- cspell:ignore cstride darkred labelpad matexpr rstride zorder -->" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"jupyter": { | ||
"source_hidden": true | ||
}, | ||
"tags": [ | ||
"remove-cell" | ||
] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%pip install -q numpy==1.20.3 plotly==5.17.0" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"This TR tests whether the HTML build of the TR notebooks supports [Plotly](https://plotly.com/python) figures. It's a follow-up to [TR-006](006.ipynb), without the interactivity of `ipywidgets`, but with the better 3D rendering of Plotly. For more info on how Plotly figures can be embedded in Sphinx HTML builds, see [this page](https://myst-nb.readthedocs.io/en/v0.17.2/render/interactive.html#plotly) of MyST-NB (particularly the remark on [`html_js_files`](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_js_files).\n", | ||
"\n", | ||
"The following example is copied from [this tutorial](https://plotly.com/python/3d-isosurface-plots)." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\n", | ||
"import plotly.graph_objects as go\n", | ||
"\n", | ||
"X, Y, Z = np.mgrid[-5:5:40j, -5:5:40j, -5:5:40j]\n", | ||
"ellipsoid = X * X * 0.5 + Y * Y + Z * Z * 2\n", | ||
"fig = go.Figure(\n", | ||
" data=go.Isosurface(\n", | ||
" x=X.flatten(),\n", | ||
" y=Y.flatten(),\n", | ||
" z=Z.flatten(),\n", | ||
" value=ellipsoid.flatten(),\n", | ||
" isomin=5,\n", | ||
" isomax=50,\n", | ||
" surface_fill=0.4,\n", | ||
" caps=dict(x_show=False, y_show=False),\n", | ||
" slices_z=dict(\n", | ||
" show=True,\n", | ||
" locations=[\n", | ||
" -1,\n", | ||
" -3,\n", | ||
" ],\n", | ||
" ),\n", | ||
" slices_y=dict(show=True, locations=[0]),\n", | ||
" )\n", | ||
")\n", | ||
"fig.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
":::{seealso} {ref}`report/006:Plotly with ipywidgets`\n", | ||
":::" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.18" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains 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
This file contains 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