Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions IPython/core/pylabtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from io import BytesIO

from IPython.core.interactiveshell import InteractiveShell
from IPython.core.display import _pngxy
from IPython.utils.decorators import flag_calls
from IPython.utils import py3compat
Expand Down Expand Up @@ -379,3 +380,16 @@ def configure_inline_support(shell, backend):
# Setup the default figure format
select_figure_formats(shell, cfg.figure_formats, **cfg.print_figure_kwargs)

class use_backend(object):

def __init__(self, backend):
from matplotlib import pyplot
self.shell = InteractiveShell.instance()
self.old_backend = backend2gui[str(pyplot.get_backend())]
self.new_backend = backend

def __enter__(self):
gui, backend = self.shell.enable_matplotlib(self.new_backend)

def __exit__(self, type, value, tb):
gui, backend = self.shell.enable_matplotlib(self.old_backend)