Skip to content

Commit

Permalink
Make inline the default matplotlib backend
Browse files Browse the repository at this point in the history
uses MPLBACKEND env (matplotlib > 1.5).

Trigger extra IPython inline setup when inline backend is loaded.
We can't call the simpler `ip.enable_matplotlib()` here because
this will be triggered during pyplot import,
and enable_matplotlib() imports pyplot which isn't ready yet.
  • Loading branch information
minrk committed Jul 14, 2016
1 parent 76c6c81 commit 70e0968
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ipykernel/kernelapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,13 @@ def init_kernel(self):
def init_gui_pylab(self):
"""Enable GUI event loop integration, taking pylab into account."""

# Register inline backend as default
# this is higher priority than matplotlibrc,
# but lower priority than anything else (mpl.use() for instance).
# This only affects matplotlib >= 1.5
if not os.environ.get('MPLBACKEND'):
os.environ['MPLBACKEND'] = 'module://ipykernel.pylab.backend_inline'

# Provide a wrapper for :meth:`InteractiveShellApp.init_gui_pylab`
# to ensure that any exception is printed straight to stderr.
# Normally _showtraceback associates the reply with an execution,
Expand Down
11 changes: 11 additions & 0 deletions ipykernel/pylab/backend_inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,14 @@ def flush_figures():
# figurecanvas. This is set here to a Agg canvas
# See https://github.com/matplotlib/matplotlib/pull/1125
FigureCanvas = FigureCanvasAgg

def _enable_matplotlib_integration():
"""Enable extra IPython matplotlib integration when we are loaded as the matplotlib backend."""
from matplotlib import get_backend
from IPython.core.pylabtools import configure_inline_support
ip = get_ipython()
backend = get_backend()
if ip and backend == 'module://%s' % __name__:
configure_inline_support(ip, backend)

_enable_matplotlib_integration()

0 comments on commit 70e0968

Please sign in to comment.