diff --git a/README.md b/README.md index 527ed6f..d9cd1ed 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![PyPI version](https://badge.fury.io/py/open-atmos-jupyter-utils.svg)](https://pypi.org/project/open-atmos-jupyter-utils) Utility routines used in 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: -- [``show_plot()``](https://open-atmos.github.io/jupyter-utils/show_plot.html) - a drop-in replacement for matplotlib's show() displaying the figure using vector graphics (svg) by default and offering a download-as-pdf widget just below (on Colab the widget triggers Google Drive download) +- [``show_plot()``](https://open-atmos.github.io/jupyter-utils/show_plot.html) - a drop-in replacement for matplotlib's show() displaying the figure inline using vector graphics (svg) by default and offering a download-as-pdf-or-svg widget just below (on Colab the widget triggers Google Drive download) - [``TemporaryFile``](https://open-atmos.github.io/jupyter-utils/temporary_file.html) - a class equipped with ``make_link_widget()`` method returning a click-to-download Colab-compatible widget to be display()-ed in a Jupyter notebook - [``pip_install_on_colab('package_a', 'package_b', ...)``](https://open-atmos.github.io/jupyter-utils/pip_install_on_colab.html) - a function handling execution of ``pip`` (and ``ldconfig``) on Colab diff --git a/open_atmos_jupyter_utils/show_plot.py b/open_atmos_jupyter_utils/show_plot.py index 75d922b..30017ad 100644 --- a/open_atmos_jupyter_utils/show_plot.py +++ b/open_atmos_jupyter_utils/show_plot.py @@ -1,6 +1,7 @@ # pylint: disable=missing-module-docstring from matplotlib import pyplot +from ipywidgets import HBox from IPython.display import display from IPython.core.interactiveshell import InteractiveShell from IPython.core.pylabtools import select_figure_formats @@ -8,7 +9,8 @@ def show_plot(filename=None, fig=pyplot, inline_format='svg'): - """ the missing click-to-save-as-pdf button for matplotlib/Jupyter (use instead of *.show()) """ + """ the missing click-to-save-as-pdf-or-svg button for matplotlib/Jupyter + (use instead of *.show()) """ link = save_and_make_link(fig, filename) select_figure_formats(InteractiveShell.instance(), {inline_format}) pyplot.show() @@ -17,6 +19,12 @@ def show_plot(filename=None, fig=pyplot, inline_format='svg'): def save_and_make_link(fig, filename=None): """ saves a figure as pdf and returns a Jupyter display()-able click-to-download widget """ - temporary_file = TemporaryFile(suffix='.pdf', filename=filename) - fig.savefig(temporary_file.absolute_path, bbox_inches='tight') - return temporary_file.make_link_widget() + temporary_files = [ + TemporaryFile(suffix=suffix, filename=( + filename if filename is None or not filename.endswith('.pdf') else filename[:-4] + ) + suffix) + for suffix in ('.pdf', '.svg') + ] + for temporary_file in temporary_files: + fig.savefig(temporary_file.absolute_path, bbox_inches='tight') + return HBox([temporary_file.make_link_widget() for temporary_file in temporary_files]) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..610b323 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,11 @@ +[tool.setuptools_scm] + +# TODO +[build-system] +requires = ['setuptools==56.0.0', 'setuptools-scm==6.0.1'] + +[project.urls] +"Homepage" = "https://github.com/open-atmos/jupyter-utils" +"Source" = "https://github.com/open-atmos/jupyter-utils" +"Tracker" = "https://github.com/open-atmos/jupyter-utils/issues" +"Documentation" = "https://open-atmos.github.io/jupyter-utils" diff --git a/setup.py b/setup.py index c4610fd..be1596e 100644 --- a/setup.py +++ b/setup.py @@ -26,9 +26,5 @@ def get_long_description(): packages=find_packages(include=['open_atmos_jupyter_utils', 'open_atmos_jupyter_utils.*']), long_description=get_long_description(), long_description_content_type="text/markdown", - project_urls={ - "Tracker": "https://github.com/open-atmos/jupyter-utils/issues", - "Documentation": "https://open-atmos.github.io/jupyter-utils", - "Source": "https://github.com/open-atmos/jupyter-utils" - } + url='https://github.com/open-atmos/jupyter-utils', )