MCPcopy Create free account
hub / github.com/ipython/ipython / enable_matplotlib

Method enable_matplotlib

IPython/core/interactiveshell.py:3471–3514  ·  view source on GitHub ↗

Enable interactive matplotlib and inline figure support. This takes the following steps: 1. select the appropriate eventloop and matplotlib backend 2. set up matplotlib for interactive use with that backend 3. configure formatters for inline figure d

(self, gui=None)

Source from the content-addressed store, hash-verified

3469 raise NotImplementedError('Implement enable_gui in a subclass')
3470
3471 def enable_matplotlib(self, gui=None):
3472 """Enable interactive matplotlib and inline figure support.
3473
3474 This takes the following steps:
3475
3476 1. select the appropriate eventloop and matplotlib backend
3477 2. set up matplotlib for interactive use with that backend
3478 3. configure formatters for inline figure display
3479 4. enable the selected gui eventloop
3480
3481 Parameters
3482 ----------
3483 gui : optional, string
3484 If given, dictates the choice of matplotlib GUI backend to use
3485 (should be one of IPython's supported backends, 'qt', 'osx', 'tk',
3486 'gtk', 'wx' or 'inline'), otherwise we use the default chosen by
3487 matplotlib (as dictated by the matplotlib build-time options plus the
3488 user's matplotlibrc configuration file). Note that not all backends
3489 make sense in all contexts, for example a terminal ipython can't
3490 display figures inline.
3491 """
3492 from IPython.core import pylabtools as pt
3493 gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select)
3494
3495 if gui != 'inline':
3496 # If we have our first gui selection, store it
3497 if self.pylab_gui_select is None:
3498 self.pylab_gui_select = gui
3499 # Otherwise if they are different
3500 elif gui != self.pylab_gui_select:
3501 print('Warning: Cannot change to a different GUI toolkit: %s.'
3502 ' Using %s instead.' % (gui, self.pylab_gui_select))
3503 gui, backend = pt.find_gui_and_backend(self.pylab_gui_select)
3504
3505 pt.activate_matplotlib(backend)
3506 pt.configure_inline_support(self, backend)
3507
3508 # Now we must activate the gui pylab wants to use, and fix %run to take
3509 # plot updates into account
3510 self.enable_gui(gui)
3511 self.magics_manager.registry['ExecutionMagics'].default_runner = \
3512 pt.mpl_runner(self.safe_execfile)
3513
3514 return gui, backend
3515
3516 def enable_pylab(self, gui=None, import_all=True, welcome_message=False):
3517 """Activate pylab support at runtime.

Callers 6

enable_pylabMethod · 0.95
test_qtMethod · 0.80
test_inlineMethod · 0.80
test_inline_twiceMethod · 0.80
test_qt_gtkMethod · 0.80
matplotlibMethod · 0.80

Calls 1

enable_guiMethod · 0.95

Tested by 4

test_qtMethod · 0.64
test_inlineMethod · 0.64
test_inline_twiceMethod · 0.64
test_qt_gtkMethod · 0.64