Skip to content

Commit 6c91c8e

Browse files
committed
Update exporting plotly as html
1 parent 0c792d2 commit 6c91c8e

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

notebooks/python/python-datavis.ipynb

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@
174174
"\n",
175175
"A nice option to visualize the statistical distribution of a data set are [**box plots**](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.boxplot.html). The _box_ itself includes by definition the central 50% of the data. Thereby, the blue box includes all data points from the 0.25-quantile (Q1) to the 0.75-quantile (Q3). Its length is called _interquantile range_ (IQR). \n",
176176
"\n",
177-
"![](https://upload.wikimedia.org/wikipedia/commons/thumb/1/1a/Boxplot_vs_PDF.svg/704px-Boxplot_vs_PDF.svg.png)\n",
178-
"[_Source_: Wikimedia Commons](https://commons.wikimedia.org/wiki/File:Boxplot_vs_PDF.svg)\n"
177+
"![](https://upload.wikimedia.org/wikipedia/commons/1/1a/Boxplot_vs_PDF.svg)\n",
178+
"[_Source_: Wikimedia Commons](https://commons.wikimedia.org/wiki/File:Boxplot_vs_PDF.svg)"
179179
]
180180
},
181181
{
@@ -430,6 +430,7 @@
430430
"outputs": [],
431431
"source": [
432432
"fig = px.scatter(df, x=df[\"alcohol\"], y=df[\"residual sugar\"])\n",
433+
"# fig.show()\n",
433434
"fig.show()"
434435
]
435436
},
@@ -438,16 +439,43 @@
438439
"id": "09289e92",
439440
"metadata": {},
440441
"source": [
441-
"## Export notebook as HTML\n",
442-
"One cool thing about `plotly` is that it is based on web technologies. When you export the notebook as HTML and open the exported HTML in a standard browser, you will find the plot not integrated as a simple image but as an interactive plot with active JavaScript. But keep in mind, that the data now has to be somehow saved within the file and will blow up your file size!"
442+
"# Export notebook as HTML\n",
443+
"One cool thing about `plotly` is that it is based on web technologies. When you export the notebook as HTML and open the exported HTML file in a standard browser, the plot is not embedded as a simple image but as a fully interactive visualization powered by JavaScript. Keep in mind, however, that the underlying data must be stored inside the HTML file, which can significantly increase the file size.\n",
444+
"\n",
445+
"Recently, there have been changes in `Plotly`. Whether the HTML export preserves interactivity now depends on your versions of Jupyter and Plotly. For this notebook, you have to switch the renderer to `notebook_connected` — then displaying plots directly in the notebook as well as in the HTML export should work. If it does not, revert to the default setting: `plotly_mimetype`.\n",
446+
"\n",
447+
"```\n",
448+
"import plotly.io as pio\n",
449+
"pio.renderers.default = \"notebook_connected\"\n",
450+
"```"
451+
]
452+
},
453+
{
454+
"cell_type": "markdown",
455+
"id": "204231d0-4f99-41ce-8f09-10bd5fdd4352",
456+
"metadata": {},
457+
"source": [
458+
"## Save plotly plot\n",
459+
"You can keep the interactivity even when saving the plot as HTML."
460+
]
461+
},
462+
{
463+
"cell_type": "code",
464+
"execution_count": null,
465+
"id": "35ba77e5-7a65-4b5b-b509-ca41ea35c35a",
466+
"metadata": {},
467+
"outputs": [],
468+
"source": [
469+
"fig = px.scatter(df, x=df[\"alcohol\"], y=df[\"residual sugar\"])\n",
470+
"fig.write_html(\"plot.html\")"
443471
]
444472
},
445473
{
446474
"cell_type": "markdown",
447475
"id": "fa7b243b",
448476
"metadata": {},
449477
"source": [
450-
"### Matplotlib-style parameters"
478+
"# Matplotlib-style parameters"
451479
]
452480
},
453481
{
@@ -477,7 +505,7 @@
477505
"id": "ea1316f1",
478506
"metadata": {},
479507
"source": [
480-
"## Plotting Exercise:"
508+
"# Plotting Exercise:"
481509
]
482510
},
483511
{

0 commit comments

Comments
 (0)