From b3469006d43d20bd58842e4302c44068aabc7e22 Mon Sep 17 00:00:00 2001 From: Tom van Woudenberg Date: Fri, 19 Dec 2025 13:55:25 +0100 Subject: [PATCH] reorder --- book/features/plotly.ipynb | 102 +++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 54 deletions(-) diff --git a/book/features/plotly.ipynb b/book/features/plotly.ipynb index 0f0a451..8f81598 100644 --- a/book/features/plotly.ipynb +++ b/book/features/plotly.ipynb @@ -16,14 +16,60 @@ "\n", "# Interactive plots: plotly\n", "\n", - "The use of the [plotly](https://plotly.com/python/getting-started/) package is an example which allows you to create HTML/Javascript widgets from python code without any knowledge on HTML/Javascript." + "The use of the [plotly](https://plotly.com/python/getting-started/) package is an example which allows you to create HTML/Javascript widgets from python code without any knowledge on HTML/Javascript. The example below is taken from the FEM-module by Frans van der Meer." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If you want to create the plot during the build of the book, don't use `fig.show()` but use the code below:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from IPython import get_ipython\n", + "from IPython.display import HTML\n", + "\n", + "def show_plotly(fig):\n", + " ip = get_ipython()\n", + " if ip is None:\n", + " return fig\n", + "\n", + " # Sphinx / Jupyter Book execution\n", + " if \"sphinx\" in ip.config:\n", + " return HTML(fig.to_html(include_plotlyjs=\"cdn\"))\n", + "\n", + " # Local execution in Jupyter Notebook / JupyterLab / VS Code\n", + " fig.show()\n", + "\n", + "....\n", + "\n", + "show_plotly(fig)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Make sure you have in your `_config.yml`:\n", + "\n", + "```yaml\n", + "execute:\n", + " execute_notebooks: \"auto\"\n", + "```\n", + "\n", + "Eventually in combination with [](../_git/github.com_TeachBooks_Sphinx-NB-Execution-Patterns/Manual/README.md)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "The example below is taken from the FEM-module by Frans van der Meer.\n", "When using Plotly graphs, make sure the notebook is executed in Jupyter Lab / Jupyter Notebook for the figures to be shown in the book. Running the code in VS code might break the result in the book, although the output is visible in VS code. Alternatively, add the following lines of code to your notebook to have a valid output in the book as well:\n", "\n", "```python\n", @@ -437,58 +483,6 @@ "\n", "fig.show()" ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "If you want to create the plot during the build of the book, don't use `fig.show()` but use the code below:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from IPython import get_ipython\n", - "from IPython.display import HTML\n", - "\n", - "def show_plotly(fig):\n", - " ip = get_ipython()\n", - " if ip is None:\n", - " return fig\n", - "\n", - " # Sphinx / Jupyter Book execution\n", - " if \"sphinx\" in ip.config:\n", - " return HTML(fig.to_html(include_plotlyjs=\"cdn\"))\n", - "\n", - " # Local execution in Jupyter Notebook / JupyterLab / VS Code\n", - " fig.show()\n", - "\n", - "....\n", - "\n", - "show_plotly(fig)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Make sure you have in your `_config.yml`:\n", - "\n", - "```yaml\n", - "execute:\n", - " execute_notebooks: \"auto\"\n", - "```" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Eventually in combination with [](../_git/github.com_TeachBooks_Sphinx-NB-Execution-Patterns/Manual/README.md)" - ] } ], "metadata": {