https://github.com/open-atmos/jupyter-utils
utility routines for embedding vector graphics and animations in Python Jupyter notebooks using matplotlib (with focus on testing and Colab & GitHub compatibility)
https://github.com/open-atmos/jupyter-utils
animations colab jupyter-notebook matplotlib pip pypi-package python testing vector-graphics
Last synced: 17 days ago
JSON representation
utility routines for embedding vector graphics and animations in Python Jupyter notebooks using matplotlib (with focus on testing and Colab & GitHub compatibility)
- Host: GitHub
- URL: https://github.com/open-atmos/jupyter-utils
- Owner: open-atmos
- License: gpl-3.0
- Created: 2021-09-16T19:28:51.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-02-04T07:20:16.000Z (3 months ago)
- Last Synced: 2025-04-14T21:13:05.245Z (17 days ago)
- Topics: animations, colab, jupyter-notebook, matplotlib, pip, pypi-package, python, testing, vector-graphics
- Language: Python
- Homepage:
- Size: 803 KB
- Stars: 4
- Watchers: 2
- Forks: 4
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# open-atmos-jupyter-utils
[](https://www.gnu.org/licenses/gpl-3.0.html)
[](https://github.com/open-atmos/jupyter-utils/actions/workflows/tests.yml)
[](https://pypi.org/project/open-atmos-jupyter-utils)
[](https://github.com/open-atmos/jupyter-utils)## Features
`open-atmos-jupyter-utils` is a Python package providing Jupyter notebook utility routines
for:
- presenting [matplotlib](https://matplotlib.org) plots as either SVG vector graphics or animated GIFs, embedding them within the notebooks, and rendering correctly in [GitHub's Rich Jupyter Notebook diffs](https://github.blog/changelog/2023-03-01-feature-preview-rich-jupyter-notebook-diffs/)
- save-as buttons below each figure (triggering [Google-Drive downloads](https://colab.research.google.com/notebooks/io.ipynb#scrollTo=hauvGV4hV-Mh) on [Colab](https://colab.google/))
- execution of unmodified notebook code for automated testing (e.g., within [pytest fixtures](https://docs.pytest.org/en/stable/explanation/fixtures.html))
- pip-installation of external packages on Colab safeguarded against [alterations of Google-shipped packages](https://github.com/googlecolab/colabtools/issues/2837)## Functions and Examples
- [``show_plot()``](https://open-atmos.github.io/jupyter-utils/open_atmos_jupyter_utils/show_plot.html) - a drop-in replacement for matplotlib.pyplot.show() that displays figures inline as SVG vector graphics. The function also provides a download widget that allows users to download the figure as PDF or SVG. On Google Colab, the widget triggers a Google Drive download. Example:
[](https://github.com/open-atmos/jupyter-utils/blob/main/examples/show_plot.ipynb)
[](https://mybinder.org/v2/gh/open-atmos/jupyter-utils.git/main?urlpath=lab/tree/examples/show_plot.ipynb)
[](https://colab.research.google.com/github/open-atmos/jupyter-utils/blob/main/examples/show_plot.ipynb)
- [``show_anim(plot_func: typing.Callable, frame_range: typing.Iterable)``](https://open-atmos.github.io/jupyter-utils/open_atmos_jupyter_utils/show_anim.html) - a replacement for matplotlib.animation.FuncAnimation that displays inline animations in GIF format (which is compatible with GitHub rendering). It also provides a download widget to save the animation as a GIF file, with Colab support for Google Drive download. Example:
[](https://github.com/open-atmos/jupyter-utils/blob/main/examples/show_anim.ipynb)
[](https://mybinder.org/v2/gh/open-atmos/jupyter-utils.git/main?urlpath=lab/tree/examples/show_anim.ipynb)
[](https://colab.research.google.com/github/open-atmos/jupyter-utils/blob/main/examples/show_anim.ipynb)
- [``notebook_vars(notebook: pathlib.Path, plot: bool)``](https://open-atmos.github.io/jupyter-utils/open_atmos_jupyter_utils/notebook_vars) - a function that executes notebook code and returns a dictionary of variables present in the notebook. This is particularly useful for setting up automated tests using pytest fixtures without any modification to the original notebooks. The `plot` flag controls if `show_plot()` calls within the notebook should be run or not. Example:
[](https://github.com/open-atmos/jupyter-utils/blob/main/tests/test_notebook_vars.py)
- [``pip_install_on_colab('package_a', 'package_b', ...)``](https://open-atmos.github.io/jupyter-utils/open_atmos_jupyter_utils/pip_install_on_colab.html) - a function that automates the installation of Python packages in Colab environments via pip (and ldconfig for system libraries). This ensures smooth setup for notebooks running on Colab.## Usage
For installation use:
```bash
pip install open-atmos-jupyter-utils
```
Then import inside Python project
```Python
import open_atmos_jupyter_utils as oaju
```## Documentation
Public API docs are maintained at: https://open-atmos.github.io/jupyter-utils/## Use Cases
open-atmos-jupyter-utils has been developed for and used in numerous Jupyter
notebooks in [PySDM](https://github.com/open-atmos/PySDM), [PyMPDATA](https://github.com/open-atmos/PyMPDATA) and [PyPartMC](https://github.com/open-atmos/PyPartMC) projects.