Skip to content

Commit

Permalink
Use matplotlib-inline instead of ipykernel.pylab
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed Apr 15, 2021
1 parent eb9b2bd commit 35b51cd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
37 changes: 21 additions & 16 deletions IPython/core/display.py
Expand Up @@ -371,7 +371,7 @@ def reload(self):
with gzip.open(BytesIO(data), 'rt', encoding=encoding) as fp:
encoding = None
data = fp.read()

# decode data, if an encoding was specified
# We only touch self.data once since
# subclasses such as SVG have @data.setter methods
Expand Down Expand Up @@ -1155,7 +1155,10 @@ def reload(self):

@skip_doctest
def set_matplotlib_formats(*formats, **kwargs):
"""Select figure formats for the inline backend. Optionally pass quality for JPEG.
"""
DEPRECATED
Select figure formats for the inline backend. Optionally pass quality for JPEG.
For example, this enables PNG and JPEG output with a JPEG quality of 90%::
Expand All @@ -1173,20 +1176,19 @@ def set_matplotlib_formats(*formats, **kwargs):
**kwargs
Keyword args will be relayed to ``figure.canvas.print_figure``.
"""
from IPython.core.interactiveshell import InteractiveShell
from IPython.core.pylabtools import select_figure_formats
# build kwargs, starting with InlineBackend config
kw = {}
from ipykernel.pylab.config import InlineBackend
cfg = InlineBackend.instance()
kw.update(cfg.print_figure_kwargs)
kw.update(**kwargs)
shell = InteractiveShell.instance()
select_figure_formats(shell, formats, **kw)
warnings.warn("`set_matplotlib_formats` is deprecated, directly use "
"`matplotlib_inline.backend_inline.set_matplotlib_formats()`",
DeprecationWarning, stacklevel=2)

from matplotlib_inline.backend_inline import set_matplotlib_formats as set_matplotlib_formats_orig
set_matplotlib_formats_orig(*formats, **kwargs)

@skip_doctest
def set_matplotlib_close(close=True):
"""Set whether the inline backend closes all figures automatically or not.
"""
DEPRECATED
Set whether the inline backend closes all figures automatically or not.
By default, the inline backend used in the IPython Notebook will close all
matplotlib figures automatically after each cell is run. This means that
Expand All @@ -1206,6 +1208,9 @@ def set_matplotlib_close(close=True):
Should all matplotlib figures be automatically closed after each cell is
run?
"""
from ipykernel.pylab.config import InlineBackend
cfg = InlineBackend.instance()
cfg.close_figures = close
warnings.warn("`set_matplotlib_close` is deprecated, directly use "
"`matplotlib_inline.backend_inline.set_matplotlib_close()`",
DeprecationWarning, stacklevel=2)

from matplotlib_inline.backend_inline import set_matplotlib_close as set_matplotlib_close_orig
set_matplotlib_close_orig(close)
6 changes: 3 additions & 3 deletions IPython/core/pylabtools.py
Expand Up @@ -25,7 +25,7 @@
'svg': 'svg',
'pdf': 'pdf',
'ps': 'ps',
'inline': 'module://ipykernel.pylab.backend_inline',
'inline': 'module://matplotlib_inline.backend_inline',
'ipympl': 'module://ipympl.backend_nbagg',
'widget': 'module://ipympl.backend_nbagg',
}
Expand All @@ -49,7 +49,7 @@
del backend2gui['svg']
del backend2gui['pdf']
del backend2gui['ps']
del backend2gui['module://ipykernel.pylab.backend_inline']
del backend2gui['module://matplotlib_inline.backend_inline']

#-----------------------------------------------------------------------------
# Matplotlib utilities
Expand Down Expand Up @@ -274,7 +274,7 @@ def find_gui_and_backend(gui=None, gui_select=None):
Returns
-------
A tuple of (gui, backend) where backend is one of ('TkAgg','GTKAgg',
'WXAgg','Qt4Agg','module://ipykernel.pylab.backend_inline','agg').
'WXAgg','Qt4Agg','module://matplotlib_inline.backend_inline','agg').
"""

import matplotlib
Expand Down
2 changes: 1 addition & 1 deletion IPython/core/tests/test_display.py
Expand Up @@ -135,7 +135,7 @@ def test_image_filename_defaults():
nt.assert_is_none(img._repr_jpeg_())

def _get_inline_config():
from ipykernel.pylab.config import InlineBackend
from matplotlib_inline.config import InlineBackend
return InlineBackend.instance()


Expand Down
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -200,6 +200,7 @@
'pygments',
'backcall',
'stack_data',
'matplotlib-inline',
]

# Platform-specific dependencies:
Expand Down

0 comments on commit 35b51cd

Please sign in to comment.