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

Function mpl_runner

IPython/core/pylabtools.py:151–196  ·  view source on GitHub ↗

Factory to return a matplotlib-enabled runner for %run. Parameters ---------- safe_execfile : function This must be a function with the same interface as the :meth:`safe_execfile` method of IPython. Returns ------- A function suitable for use as the ``runner`` a

(safe_execfile)

Source from the content-addressed store, hash-verified

149# We need a little factory function here to create the closure where
150# safe_execfile can live.
151def mpl_runner(safe_execfile):
152 """Factory to return a matplotlib-enabled runner for %run.
153
154 Parameters
155 ----------
156 safe_execfile : function
157 This must be a function with the same interface as the
158 :meth:`safe_execfile` method of IPython.
159
160 Returns
161 -------
162 A function suitable for use as the ``runner`` argument of the %run magic
163 function.
164 """
165
166 def mpl_execfile(fname,*where,**kw):
167 """matplotlib-aware wrapper around safe_execfile.
168
169 Its interface is identical to that of the :func:`execfile` builtin.
170
171 This is ultimately a call to execfile(), but wrapped in safeties to
172 properly handle interactive rendering."""
173
174 import matplotlib
175 import matplotlib.pyplot as plt
176
177 #print '*** Matplotlib runner ***' # dbg
178 # turn off rendering until end of script
179 is_interactive = matplotlib.rcParams['interactive']
180 matplotlib.interactive(False)
181 safe_execfile(fname,*where,**kw)
182 matplotlib.interactive(is_interactive)
183 # make rendering call now, if the user tried to do it
184 if plt.draw_if_interactive.called:
185 plt.draw()
186 plt.draw_if_interactive.called = False
187
188 # re-draw everything that is stale
189 try:
190 da = plt.draw_all
191 except AttributeError:
192 pass
193 else:
194 da()
195
196 return mpl_execfile
197
198
199def _reshow_nbagg_figure(fig):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected