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

Method enable_pylab

IPython/core/interactiveshell.py:3516–3558  ·  view source on GitHub ↗

Activate pylab support at runtime. This turns on support for matplotlib, preloads into the interactive namespace all of numpy and pylab, and configures IPython to correctly interact with the GUI event loop. The GUI backend to be used can be optionally selected with

(self, gui=None, import_all=True, welcome_message=False)

Source from the content-addressed store, hash-verified

3514 return gui, backend
3515
3516 def enable_pylab(self, gui=None, import_all=True, welcome_message=False):
3517 """Activate pylab support at runtime.
3518
3519 This turns on support for matplotlib, preloads into the interactive
3520 namespace all of numpy and pylab, and configures IPython to correctly
3521 interact with the GUI event loop. The GUI backend to be used can be
3522 optionally selected with the optional ``gui`` argument.
3523
3524 This method only adds preloading the namespace to InteractiveShell.enable_matplotlib.
3525
3526 Parameters
3527 ----------
3528 gui : optional, string
3529 If given, dictates the choice of matplotlib GUI backend to use
3530 (should be one of IPython's supported backends, 'qt', 'osx', 'tk',
3531 'gtk', 'wx' or 'inline'), otherwise we use the default chosen by
3532 matplotlib (as dictated by the matplotlib build-time options plus the
3533 user's matplotlibrc configuration file). Note that not all backends
3534 make sense in all contexts, for example a terminal ipython can't
3535 display figures inline.
3536 import_all : optional, bool, default: True
3537 Whether to do `from numpy import *` and `from pylab import *`
3538 in addition to module imports.
3539 welcome_message : deprecated
3540 This argument is ignored, no welcome message will be displayed.
3541 """
3542 from IPython.core.pylabtools import import_pylab
3543
3544 gui, backend = self.enable_matplotlib(gui)
3545
3546 # We want to prevent the loading of pylab to pollute the user's
3547 # namespace as shown by the %who* magics, so we execute the activation
3548 # code in an empty namespace, and we update *both* user_ns and
3549 # user_ns_hidden with this information.
3550 ns = {}
3551 import_pylab(ns, import_all)
3552 # warn about clobbered names
3553 ignored = {"__builtins__"}
3554 both = set(ns).intersection(self.user_ns).difference(ignored)
3555 clobbered = [ name for name in both if self.user_ns[name] is not ns[name] ]
3556 self.user_ns.update(ns)
3557 self.user_ns_hidden.update(ns)
3558 return gui, backend, clobbered
3559
3560 #-------------------------------------------------------------------------
3561 # Utilities

Callers 2

init_gui_pylabMethod · 0.80
pylabMethod · 0.80

Calls 3

enable_matplotlibMethod · 0.95
import_pylabFunction · 0.90
updateMethod · 0.45

Tested by

no test coverage detected