diff options
| author | robot-piglet <[email protected]> | 2025-11-11 16:48:16 +0300 |
|---|---|---|
| committer | robot-piglet <[email protected]> | 2025-11-11 17:12:43 +0300 |
| commit | c61d2226cd86de967ae919bd9e9b731ac48ea0de (patch) | |
| tree | 582d2d6c9892db5cd72d99602c1172220252ad22 /contrib/python/matplotlib-inline | |
| parent | 75780c9a0875bfa2c8d0dae95325811ea210a972 (diff) | |
Intermediate changes
commit_hash:684f14a6f19a735297e2d00229b9bc1d7b46e18a
Diffstat (limited to 'contrib/python/matplotlib-inline')
7 files changed, 111 insertions, 92 deletions
diff --git a/contrib/python/matplotlib-inline/.dist-info/METADATA b/contrib/python/matplotlib-inline/.dist-info/METADATA index 2046024a647..c0aef502d2e 100644 --- a/contrib/python/matplotlib-inline/.dist-info/METADATA +++ b/contrib/python/matplotlib-inline/.dist-info/METADATA @@ -1,61 +1,37 @@ -Metadata-Version: 2.1 +Metadata-Version: 2.4 Name: matplotlib-inline -Version: 0.1.7 +Version: 0.2.1 Summary: Inline Matplotlib backend for Jupyter -Author-email: IPython Development Team <[email protected]> -License: BSD 3-Clause License - - Copyright (c) 2019-2022, IPython Development Team. - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -Project-URL: Homepage, https://github.com/ipython/matplotlib-inline Keywords: ipython,jupyter,matplotlib,python +Author-email: IPython Development Team <[email protected]> +Requires-Python: >=3.9 +Description-Content-Type: text/markdown Classifier: Development Status :: 5 - Production/Stable Classifier: Framework :: IPython -Classifier: Framework :: Jupyter -Classifier: Framework :: Jupyter :: JupyterLab Classifier: Framework :: Jupyter :: JupyterLab :: 3 Classifier: Framework :: Jupyter :: JupyterLab :: 4 +Classifier: Framework :: Jupyter :: JupyterLab +Classifier: Framework :: Jupyter Classifier: Intended Audience :: Developers Classifier: Intended Audience :: Science/Research -Classifier: License :: OSI Approved :: BSD License -Classifier: Programming Language :: Python -Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.8 -Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: 3.11 Classifier: Programming Language :: Python :: 3.12 +Classifier: Programming Language :: Python :: 3.13 +Classifier: Programming Language :: Python :: 3.14 +Classifier: Programming Language :: Python :: 3.9 +Classifier: Programming Language :: Python :: 3 +Classifier: Programming Language :: Python Classifier: Topic :: Multimedia :: Graphics -Requires-Python: >=3.8 -Description-Content-Type: text/markdown License-File: LICENSE Requires-Dist: traitlets +Requires-Dist: flake8 ; extra == "test" +Requires-Dist: nbdime ; extra == "test" +Requires-Dist: nbval ; extra == "test" +Requires-Dist: notebook ; extra == "test" +Requires-Dist: pytest ; extra == "test" +Project-URL: Homepage, https://github.com/ipython/matplotlib-inline +Provides-Extra: test # Matplotlib Inline Back-end for IPython and Jupyter @@ -95,3 +71,4 @@ plt.title('A simple chirp'); ## License Licensed under the terms of the BSD 3-Clause License, by the IPython Development Team (see `LICENSE` file). + diff --git a/contrib/python/matplotlib-inline/.dist-info/entry_points.txt b/contrib/python/matplotlib-inline/.dist-info/entry_points.txt index cc52c3383b6..7a26e3855c1 100644 --- a/contrib/python/matplotlib-inline/.dist-info/entry_points.txt +++ b/contrib/python/matplotlib-inline/.dist-info/entry_points.txt @@ -1,2 +1,3 @@ [matplotlib.backend] -inline = matplotlib_inline.backend_inline +inline=matplotlib_inline.backend_inline + diff --git a/contrib/python/matplotlib-inline/matplotlib_inline/__init__.py b/contrib/python/matplotlib-inline/matplotlib_inline/__init__.py index dce942f8991..d275175ecd9 100644 --- a/contrib/python/matplotlib-inline/matplotlib_inline/__init__.py +++ b/contrib/python/matplotlib-inline/matplotlib_inline/__init__.py @@ -1,2 +1,8 @@ from . import backend_inline, config # noqa -__version__ = "0.1.7" # noqa + +__version__ = "0.2.1" + +# we can't ''.join(...) otherwise finding the version number at build time requires +# import which introduces IPython and matplotlib at build time, and thus circular +# dependencies. +version_info = tuple(int(s) for s in __version__.split(".")[:3]) diff --git a/contrib/python/matplotlib-inline/matplotlib_inline/backend_inline.py b/contrib/python/matplotlib-inline/matplotlib_inline/backend_inline.py index 05554b0d223..a798c562a7f 100644 --- a/contrib/python/matplotlib-inline/matplotlib_inline/backend_inline.py +++ b/contrib/python/matplotlib-inline/matplotlib_inline/backend_inline.py @@ -4,17 +4,16 @@ # Distributed under the terms of the BSD 3-Clause License. import matplotlib +from IPython.core.getipython import get_ipython +from IPython.core.interactiveshell import InteractiveShell +from IPython.core.pylabtools import select_figure_formats +from IPython.display import display from matplotlib import colors +from matplotlib._pylab_helpers import Gcf from matplotlib.backends import backend_agg from matplotlib.backends.backend_agg import FigureCanvasAgg -from matplotlib._pylab_helpers import Gcf from matplotlib.figure import Figure -from IPython.core.interactiveshell import InteractiveShell -from IPython.core.getipython import get_ipython -from IPython.core.pylabtools import select_figure_formats -from IPython.display import display - from .config import InlineBackend @@ -43,10 +42,11 @@ def new_figure_manager_given_figure(num, figure): # https://github.com/ipython/ipython/issues/1612 # https://github.com/matplotlib/matplotlib/issues/835 - if not hasattr(figure, 'show'): + if not hasattr(figure, "show"): # Queue up `figure` for display figure.show = lambda *a: display( - figure, metadata=_fetch_figure_metadata(figure)) + figure, metadata=_fetch_figure_metadata(figure) + ) # If matplotlib was manually set to non-interactive mode, this function # should be a no-op (otherwise we'll generate duplicate plots, since a user @@ -89,20 +89,20 @@ def show(close=None, block=None): for figure_manager in Gcf.get_all_fig_managers(): display( figure_manager.canvas.figure, - metadata=_fetch_figure_metadata(figure_manager.canvas.figure) + metadata=_fetch_figure_metadata(figure_manager.canvas.figure), ) finally: show._to_draw = [] # only call close('all') if any to close # close triggers gc.collect, which can be slow if close and Gcf.get_all_fig_managers(): - matplotlib.pyplot.close('all') + matplotlib.pyplot.close("all") # This flag will be reset by draw_if_interactive when called -show._draw_called = False +show._draw_called = False # type: ignore[attr-defined] # list of figures to draw when flush_figures is called -show._to_draw = [] +show._to_draw = [] # type: ignore[attr-defined] def flush_figures(): @@ -176,8 +176,8 @@ def configure_inline_support(shell, backend): if cfg not in shell.configurables: shell.configurables.append(cfg) - if backend in ('inline', 'module://matplotlib_inline.backend_inline'): - shell.events.register('post_execute', flush_figures) + if backend in ("inline", "module://matplotlib_inline.backend_inline"): + shell.events.register("post_execute", flush_figures) # Save rcParams that will be overwrittern shell._saved_rcParams = {} @@ -188,10 +188,10 @@ def configure_inline_support(shell, backend): new_backend_name = "inline" else: try: - shell.events.unregister('post_execute', flush_figures) + shell.events.unregister("post_execute", flush_figures) except ValueError: pass - if hasattr(shell, '_saved_rcParams'): + if hasattr(shell, "_saved_rcParams"): matplotlib.rcParams.update(shell._saved_rcParams) del shell._saved_rcParams new_backend_name = "other" @@ -208,11 +208,18 @@ def configure_inline_support(shell, backend): def _enable_matplotlib_integration(): """Enable extra IPython matplotlib integration when we are loaded as the matplotlib backend.""" - from matplotlib import get_backend ip = get_ipython() - backend = get_backend() - if ip and backend in ('inline', 'module://matplotlib_inline.backend_inline'): + + import matplotlib + + if matplotlib.__version_info__ >= (3, 10): + backend = matplotlib.get_backend(auto_select=False) + else: + backend = matplotlib.rcParams._get("backend") + + if ip and backend in ("inline", "module://matplotlib_inline.backend_inline"): from IPython.core.pylabtools import activate_matplotlib + try: activate_matplotlib(backend) configure_inline_support(ip, backend) @@ -221,8 +228,9 @@ def _enable_matplotlib_integration(): def configure_once(*args): activate_matplotlib(backend) configure_inline_support(ip, backend) - ip.events.unregister('post_run_cell', configure_once) - ip.events.register('post_run_cell', configure_once) + ip.events.unregister("post_run_cell", configure_once) + + ip.events.register("post_run_cell", configure_once) _enable_matplotlib_integration() @@ -233,13 +241,17 @@ def _fetch_figure_metadata(fig): # determine if a background is needed for legibility if _is_transparent(fig.get_facecolor()): # the background is transparent - ticksLight = _is_light([label.get_color() - for axes in fig.axes - for axis in (axes.xaxis, axes.yaxis) - for label in axis.get_ticklabels()]) + ticksLight = _is_light( + [ + label.get_color() + for axes in fig.axes + for axis in (axes.xaxis, axes.yaxis) + for label in axis.get_ticklabels() + ] + ) if ticksLight.size and (ticksLight == ticksLight[0]).all(): # there are one or more tick labels, all with the same lightness - return {'needs_background': 'dark' if ticksLight[0] else 'light'} + return {"needs_background": "dark" if ticksLight[0] else "light"} return None @@ -249,13 +261,13 @@ def _is_light(color): opposed to dark). Based on ITU BT.601 luminance formula (see https://stackoverflow.com/a/596241).""" rgbaArr = colors.to_rgba_array(color) - return rgbaArr[:, :3].dot((.299, .587, .114)) > .5 + return rgbaArr[:, :3].dot((0.299, 0.587, 0.114)) > 0.5 def _is_transparent(color): """Determine transparency from alpha.""" rgba = colors.to_rgba(color) - return rgba[3] < .5 + return rgba[3] < 0.5 def set_matplotlib_formats(*formats, **kwargs): @@ -263,12 +275,21 @@ def set_matplotlib_formats(*formats, **kwargs): For example, this enables PNG and JPEG output with a JPEG quality of 90%:: - In [1]: set_matplotlib_formats('png', 'jpeg', quality=90) + In [1]: set_matplotlib_formats('png', 'jpeg', + pil_kwargs={'quality': 90}) + + To set this in your notebook by `%config` magic:: + + In [1]: %config InlineBackend.figure_formats = {'png', 'jpeg'} + %config InlineBackend.print_figure_kwargs = \\ + {'pil_kwargs': {'quality' : 90}} To set this in your config files use the following:: c.InlineBackend.figure_formats = {'png', 'jpeg'} - c.InlineBackend.print_figure_kwargs.update({'quality' : 90}) + c.InlineBackend.print_figure_kwargs.update({ + 'pil_kwargs': {'quality' : 90} + }) Parameters ---------- @@ -276,6 +297,10 @@ def set_matplotlib_formats(*formats, **kwargs): One or more figure formats to enable: 'png', 'retina', 'jpeg', 'svg', 'pdf'. **kwargs Keyword args will be relayed to ``figure.canvas.print_figure``. + + In addition, see the docstrings of `plt.savefig()`, + `matplotlib.figure.Figure.savefig()`, `PIL.Image.Image.save()` and + :ref:`Pillow Image file formats <handbook/image-file-formats>`. """ # build kwargs, starting with InlineBackend config cfg = InlineBackend.instance() diff --git a/contrib/python/matplotlib-inline/matplotlib_inline/config.py b/contrib/python/matplotlib-inline/matplotlib_inline/config.py index 8718babad92..ce9be032fbd 100644 --- a/contrib/python/matplotlib-inline/matplotlib_inline/config.py +++ b/contrib/python/matplotlib-inline/matplotlib_inline/config.py @@ -6,10 +6,8 @@ This module does not import anything from matplotlib. # Copyright (c) IPython Development Team. # Distributed under the terms of the BSD 3-Clause License. +from traitlets import Bool, Dict, Instance, Set, TraitError, Unicode from traitlets.config.configurable import SingletonConfigurable -from traitlets import ( - Dict, Instance, Set, Bool, TraitError, Unicode -) # Configurable for inline backend options @@ -18,6 +16,7 @@ def pil_available(): out = False try: from PIL import Image # noqa + out = True except ImportError: pass @@ -44,37 +43,45 @@ class InlineBackend(InlineBackendConfig): the box, but third-party tools may use it to manage rc data. To change personal defaults for matplotlib, use matplotlib's configuration tools, or customize this class in your `ipython_config.py` file for - IPython/Jupyter-specific usage.""").tag(config=True) + IPython/Jupyter-specific usage.""", + ).tag(config=True) figure_formats = Set( - {'png'}, + {"png"}, help="""A set of figure formats to enable: 'png', - 'retina', 'jpeg', 'svg', 'pdf'.""").tag(config=True) + 'retina', 'jpeg', 'svg', 'pdf'.""", + ).tag(config=True) def _update_figure_formatters(self): if self.shell is not None: from IPython.core.pylabtools import select_figure_formats - select_figure_formats(self.shell, self.figure_formats, **self.print_figure_kwargs) + + select_figure_formats( + self.shell, self.figure_formats, **self.print_figure_kwargs + ) def _figure_formats_changed(self, name, old, new): - if 'jpg' in new or 'jpeg' in new: + if "jpg" in new or "jpeg" in new: if not pil_available(): raise TraitError("Requires PIL/Pillow for JPG figures") self._update_figure_formatters() - figure_format = Unicode(help="""The figure format to enable (deprecated - use `figure_formats` instead)""").tag(config=True) + figure_format = Unicode( + help="""The figure format to enable (deprecated + use `figure_formats` instead)""" + ).tag(config=True) def _figure_format_changed(self, name, old, new): if new: self.figure_formats = {new} print_figure_kwargs = Dict( - {'bbox_inches': 'tight'}, + {"bbox_inches": "tight"}, help="""Extra kwargs to be passed to fig.canvas.print_figure. - Logical examples include: bbox_inches, quality (for jpeg figures), etc. - """ + Logical examples include: bbox_inches, pil_kwargs, etc. In addition, + see the docstrings of `set_matplotlib_formats`. + """, ).tag(config=True) _print_figure_kwargs_changed = _update_figure_formatters @@ -94,7 +101,9 @@ class InlineBackend(InlineBackendConfig): iterative editing of figures, and behaves most consistently with other matplotlib backends, but figure barriers between cells must be explicit. - """).tag(config=True) + """, + ).tag(config=True) - shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', - allow_none=True) + shell = Instance( + "IPython.core.interactiveshell.InteractiveShellABC", allow_none=True + ) diff --git a/contrib/python/matplotlib-inline/matplotlib_inline/py.typed b/contrib/python/matplotlib-inline/matplotlib_inline/py.typed new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/contrib/python/matplotlib-inline/matplotlib_inline/py.typed diff --git a/contrib/python/matplotlib-inline/ya.make b/contrib/python/matplotlib-inline/ya.make index 0de287f135a..718e1ebacab 100644 --- a/contrib/python/matplotlib-inline/ya.make +++ b/contrib/python/matplotlib-inline/ya.make @@ -2,7 +2,7 @@ PY3_LIBRARY() -VERSION(0.1.7) +VERSION(0.2.1) LICENSE(BSD-3-Clause) @@ -28,6 +28,7 @@ RESOURCE_FILES( .dist-info/METADATA .dist-info/entry_points.txt .dist-info/top_level.txt + matplotlib_inline/py.typed ) END() |
