Skip to content

Commit

Permalink
DOC: add Plotly example notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Sep 25, 2023
1 parent 11be24a commit 84350d2
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 0 deletions.
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"parametrizations",
"pathlib",
"permutate",
"Plotly",
"pyproject",
"pytest",
"PYTHONHASHSEED",
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def get_minor_version(package_name: str) -> str:
None,
),
"numpy": (f"https://numpy.org/doc/{get_minor_version('numpy')}", None),
"plotly": ("https://plotly.com/python-api-reference/", None),
"pwa": ("https://pwa.readthedocs.io", None),
"python": ("https://docs.python.org/3", None),
"qrules": ("https://qrules.readthedocs.io/en/stable", None),
Expand Down
146 changes: 146 additions & 0 deletions docs/report/023.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{
"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": {},
"source": [
"````{margin}\n",
"```{spec} 3D plots with Plotly\n",
":id: TR-023\n",
":status: WIP\n",
":tags: documentation; jupyter; sphinx\n",
"\n",
"Closes [ComPWA/compwa-org#206](https://github.com/ComPWA/compwa-org/issues/206).\n",
"```\n",
"````\n",
"\n",
"# 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 {need}`TR-006`, 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()"
]
}
],
"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
}
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ruff = [
"--extend-ignore=A003",
"--extend-ignore=B008",
"--extend-ignore=B018",
"--extend-ignore=C408",
"--extend-ignore=C90",
"--extend-ignore=D",
"--extend-ignore=F404",
Expand Down

0 comments on commit 84350d2

Please sign in to comment.