##// END OF EJS Templates
Fix critical bug with pylab support inadvertently introduced in #648....
Fernando Perez -
Show More
@@ -247,7 +247,11 b' def import_pylab(user_ns, backend, import_all=True, shell=None):'
247 exec s in user_ns
247 exec s in user_ns
248
248
249 if shell is not None:
249 if shell is not None:
250 exec s in shell.user_ns_hidden
250 # All local executions are done in a fresh namespace and we then update
251 # the set of 'hidden' keys so these variables don't show up in %who
252 # (which is meant to show only what the user has manually defined).
253 ns = {}
254 exec s in ns
251 # If using our svg payload backend, register the post-execution
255 # If using our svg payload backend, register the post-execution
252 # function that will pick up the results for display. This can only be
256 # function that will pick up the results for display. This can only be
253 # done with access to the real shell object.
257 # done with access to the real shell object.
@@ -268,7 +272,7 b' def import_pylab(user_ns, backend, import_all=True, shell=None):'
268
272
269 # Add 'figsize' to pyplot and to the user's namespace
273 # Add 'figsize' to pyplot and to the user's namespace
270 user_ns['figsize'] = pyplot.figsize = figsize
274 user_ns['figsize'] = pyplot.figsize = figsize
271 shell.user_ns_hidden['figsize'] = figsize
275 ns['figsize'] = figsize
272
276
273 # Setup the default figure format
277 # Setup the default figure format
274 fmt = cfg.figure_format
278 fmt = cfg.figure_format
@@ -277,17 +281,18 b' def import_pylab(user_ns, backend, import_all=True, shell=None):'
277 # The old pastefig function has been replaced by display
281 # The old pastefig function has been replaced by display
278 from IPython.core.display import display
282 from IPython.core.display import display
279 # Add display and display_png to the user's namespace
283 # Add display and display_png to the user's namespace
280 user_ns['display'] = display
284 ns['display'] = user_ns['display'] = display
281 shell.user_ns_hidden['display'] = display
285 ns['getfigs'] = user_ns['getfigs'] = getfigs
282 user_ns['getfigs'] = getfigs
283 shell.user_ns_hidden['getfigs'] = getfigs
284
286
285 if import_all:
287 if import_all:
286 s = ("from matplotlib.pylab import *\n"
288 s = ("from matplotlib.pylab import *\n"
287 "from numpy import *\n")
289 "from numpy import *\n")
288 exec s in user_ns
290 exec s in user_ns
289 if shell is not None:
291 if shell is not None:
290 exec s in shell.user_ns_hidden
292 exec s in ns
293
294 # Update the set of hidden variables with anything we've done here.
295 shell.user_ns_hidden.update(ns)
291
296
292
297
293 def pylab_activate(user_ns, gui=None, import_all=True, shell=None):
298 def pylab_activate(user_ns, gui=None, import_all=True, shell=None):
@@ -20,6 +20,7 b" import matplotlib; matplotlib.use('Agg')"
20 import nose.tools as nt
20 import nose.tools as nt
21
21
22 from matplotlib import pyplot as plt
22 from matplotlib import pyplot as plt
23 import numpy as np
23
24
24 # Our own imports
25 # Our own imports
25 from IPython.testing import decorators as dec
26 from IPython.testing import decorators as dec
@@ -52,3 +53,10 b' def test_figure_to_svg():'
52 plt.draw()
53 plt.draw()
53 svg = pt.print_figure(fig, 'svg')[:100].lower()
54 svg = pt.print_figure(fig, 'svg')[:100].lower()
54 yield nt.assert_true('doctype svg' in svg)
55 yield nt.assert_true('doctype svg' in svg)
56
57
58 def test_import_pylab():
59 ip = get_ipython()
60 pt.import_pylab(ip.user_ns, 'inline', import_all=False, shell=ip)
61 nt.assert_true('plt' in ip.user_ns)
62 nt.assert_equal(ip.user_ns['np'], np)
General Comments 0
You need to be logged in to leave comments. Login now