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

Method pylab

IPython/core/magics/pylab.py:114–161  ·  view source on GitHub ↗

Load numpy and matplotlib to work interactively. This function lets you activate pylab (matplotlib, numpy and interactive support) at any point during an IPython session. %pylab makes the following imports:: import numpy import matplotlib

(self, line='')

Source from the content-addressed store, hash-verified

112 )
113 @magic_gui_arg
114 def pylab(self, line=''):
115 """Load numpy and matplotlib to work interactively.
116
117 This function lets you activate pylab (matplotlib, numpy and
118 interactive support) at any point during an IPython session.
119
120 %pylab makes the following imports::
121
122 import numpy
123 import matplotlib
124 from matplotlib import pylab, mlab, pyplot
125 np = numpy
126 plt = pyplot
127
128 from IPython.display import display
129 from IPython.core.pylabtools import figsize, getfigs
130
131 from pylab import *
132 from numpy import *
133
134 If you pass `--no-import-all`, the last two `*` imports will be excluded.
135
136 See the %matplotlib magic for more details about activating matplotlib
137 without affecting the interactive namespace.
138 """
139 args = magic_arguments.parse_argstring(self.pylab, line)
140 if args.no_import_all is None:
141 # get default from Application
142 if Application.initialized():
143 app = Application.instance()
144 try:
145 import_all = app.pylab_import_all
146 except AttributeError:
147 import_all = True
148 else:
149 # nothing specified, no app - default True
150 import_all = True
151 else:
152 # invert no-import flag
153 import_all = not args.no_import_all
154
155 gui, backend, clobbered = self.shell.enable_pylab(args.gui, import_all=import_all)
156 self._show_matplotlib_backend(args.gui, backend)
157 print("Populating the interactive namespace from numpy and matplotlib")
158 if clobbered:
159 warn("pylab import has clobbered these variables: %s" % clobbered +
160 "\n`%matplotlib` prevents importing * from pylab and numpy"
161 )
162
163 def _show_matplotlib_backend(self, gui, backend):
164 """show matplotlib message backend message"""

Callers

nothing calls this directly

Calls 3

parse_argstringMethod · 0.80
enable_pylabMethod · 0.80

Tested by

no test coverage detected