Skip to content

Commit

Permalink
DOC: render ipympl plots as exported figures (#80)
Browse files Browse the repository at this point in the history
* DOC: improve ipympl output in Sphinx build
* DX: avoid formatting `ipynp` files with Prettier in pre-commit
* MAINT: update Jupyter notebook kernel
  • Loading branch information
redeboer authored Aug 13, 2024
1 parent 16bdcd6 commit 1f83335
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ repos:
rev: v4.0.0-alpha.8
hooks:
- id: prettier
exclude: >-
(?x)^(
.*\.ipynb
)$
- repo: https://github.com/redeboer/taplo-pre-commit
rev: 0.9.1rc1
Expand Down
2 changes: 2 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.png
*.svg
.ipynb_checkpoints
_build
19 changes: 15 additions & 4 deletions docs/eta-pi-p/automated.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"import sympy as sp\n",
"from ampform.dynamics.builder import RelativisticBreitWignerBuilder\n",
"from ampform.io import aslatex, improve_latex_rendering\n",
"from IPython.display import Math, display\n",
"from IPython.display import SVG, Math, display\n",
"from qrules.particle import Particle, Spin, create_particle, load_pdg\n",
"from tensorwaves.data import (\n",
" SympyDataTransformer,\n",
Expand All @@ -55,6 +55,8 @@
")\n",
"from tensorwaves.function.sympy import create_parametrized_function\n",
"\n",
"STATIC_PAGE = \"EXECUTE_NB\" in os.environ\n",
"\n",
"os.environ[\"TF_CPP_MIN_LOG_LEVEL\"] = \"3\"\n",
"logging.disable(logging.WARNING)\n",
"warnings.filterwarnings(\"ignore\")\n",
Expand Down Expand Up @@ -398,6 +400,9 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
"source_hidden": true
},
"tags": [
"hide-input",
"full-width",
Expand Down Expand Up @@ -470,9 +475,15 @@
"interactive_plot = w.interactive_output(update_plot, sliders)\n",
"for ax in axes:\n",
" ax.legend(fontsize=\"small\")\n",
"\n",
"fig.tight_layout()\n",
"display(UI, interactive_plot)"
"\n",
"if STATIC_PAGE:\n",
" filename = \"1d-histograms.svg\"\n",
" fig.savefig(filename)\n",
" plt.close(fig)\n",
" display(UI, SVG(filename))\n",
"else:\n",
" display(UI, interactive_plot)"
]
}
],
Expand All @@ -492,7 +503,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.12.5"
}
},
"nbformat": 4,
Expand Down
25 changes: 20 additions & 5 deletions docs/lambda-k-pi/automated.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"import sympy as sp\n",
"from ampform.dynamics.builder import RelativisticBreitWignerBuilder\n",
"from ampform.io import aslatex, improve_latex_rendering\n",
"from IPython.display import Markdown, Math, display\n",
"from IPython.display import SVG, Image, Markdown, Math, display\n",
"from qrules.particle import Particle, Spin, create_particle, load_pdg\n",
"from tensorwaves.data import (\n",
" SympyDataTransformer,\n",
Expand All @@ -60,6 +60,8 @@
")\n",
"from tensorwaves.function.sympy import create_parametrized_function\n",
"\n",
"STATIC_PAGE = \"EXECUTE_NB\" in os.environ\n",
"\n",
"os.environ[\"TF_CPP_MIN_LOG_LEVEL\"] = \"3\"\n",
"logging.disable(logging.WARNING)\n",
"warnings.filterwarnings(\"ignore\")\n",
Expand Down Expand Up @@ -650,7 +652,14 @@
"interactive_plot = w.interactive_output(update_histogram, sliders)\n",
"fig_2d.tight_layout()\n",
"fig_2d.colorbar(mesh, ax=ax_2d)\n",
"display(UI, interactive_plot)"
"\n",
"if STATIC_PAGE:\n",
" filename = \"dalitz-plot.png\"\n",
" fig_2d.savefig(filename)\n",
" plt.close(fig_2d)\n",
" display(UI, Image(filename))\n",
"else:\n",
" display(UI, interactive_plot)"
]
},
{
Expand Down Expand Up @@ -729,9 +738,15 @@
"interactive_plot = w.interactive_output(update_plot, sliders)\n",
"for ax in axes:\n",
" ax.legend(fontsize=\"small\")\n",
"\n",
"fig.tight_layout()\n",
"display(UI, interactive_plot)"
"\n",
"if STATIC_PAGE:\n",
" filename = \"histogram.svg\"\n",
" fig.savefig(filename)\n",
" plt.close(fig)\n",
" display(UI, SVG(filename))\n",
"else:\n",
" display(UI, interactive_plot)"
]
}
],
Expand All @@ -751,7 +766,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.12.5"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 1f83335

Please sign in to comment.