Update plotyl instructions

This commit is contained in:
Tom van Woudenberg 2025-12-19 13:32:17 +01:00 • committed by GitHub
parent bd4516c25e
commit 025b2ff5c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -437,6 +437,58 @@
"\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.html)"
]
}
],
"metadata": {