Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add another example #38

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 37 additions & 8 deletions _notebooks/2022-11-05-plotly-example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "ad93b0a2",
"id": "e5cbf420",
"metadata": {},
"source": [
"---\n",
Expand All @@ -22,7 +22,7 @@
"\n",
"<!--more-->\n",
"\n",
"In this post, we will see how one can:\n",
"In this post, we will see how you can:\n",
"\n",
"+ generate Jekyll posts from Jupyter notebooks;\n",
"+ include Plotly figures inside the posts;\n",
Expand All @@ -32,7 +32,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "35093584",
"id": "26202771",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -70,17 +70,18 @@
"\n",
"When executing notebooks, Plotly figures are directly included the notebook.\n",
"Because those graphics are HTML images with Javascript, including this HTML code\n",
"in markdown output can cause some issues with the Liquid templating system used by\n",
"Jekyll. This is because the generated Javascript contains curly braces,\n",
"which Liquid tries to interpret.\n",
"in the markdown output can cause some issues with the\n",
"Liquid templating system used by Jekyll.\n",
"This is because the generated Javascript contains curly braces,\n",
"which Liquid tries to interpret, but should not.\n",
"\n",
"All the steps mentioned below, and more, are performed when importing\n",
"[`_notebooks/plotting.py`{: .filepath}](https://github.com/jeertmans/jeertmans.github.io/blob/main/_notebooks/plotting.py).\n",
"\n",
"### Changing the default renderer\n",
"\n",
"Plotly offers a variety of renderers, one of which renders the Plotly figures\n",
"in separated HTML files, which are included using `iframe` tags.\n",
"in separated HTML files, that are included using `iframe` elements.\n",
"\n",
"Among the `IFrame` renderers, we will use the `iframe_connected`\n",
"renderer, that loads the necessary Plotly files from a CDN. This is useful\n",
Expand Down Expand Up @@ -308,7 +309,7 @@
},
{
"cell_type": "markdown",
"id": "dc331471",
"id": "78a0fc02",
"metadata": {},
"source": [
"### 3D Surface"
Expand Down Expand Up @@ -346,6 +347,34 @@
"\n",
"fig.show()"
]
},
{
"cell_type": "markdown",
"id": "0b772b3e",
"metadata": {},
"source": [
"### Treemap"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3d3137d4",
"metadata": {},
"outputs": [],
"source": [
"# Example from: https://plotly.com/python/plotly-express/\n",
"\n",
"df = px.data.gapminder().query(\"year == 2007\")\n",
"fig = px.treemap(\n",
" df,\n",
" path=[px.Constant(\"world\"), \"continent\", \"country\"],\n",
" values=\"pop\",\n",
" color=\"lifeExp\",\n",
" hover_data=[\"iso_alpha\"],\n",
")\n",
"fig.show()"
]
}
],
"metadata": {
Expand Down