Menu

[r8989]: / trunk / py4science / book / ipython_roadshow_extras.py  Maximize  Restore  History

Download this file

60 lines (48 with data), 2.0 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""Extra stuff for the roadshow configuration which we may want to use"""
def magic_ca(parameter_s=''):
"Simple magic wrapper to call pylab's close('all')"
pylab.close('all')
__IPYTHON__.magic_ca = magic_ca
del magic_ca
##############################################################
# HACK for Tk backends
HACK_TK = 0 # flag to control its use
# Temporary hack around a matplotlib figure closing bug, remove when the bug
# is fixed. The bug involves matplotlib destroying Mayavi windows it
# shouldn't, which crashes VTK if close('all') is called.
if HACK_TK and matplotlib.rcParams['backend'].startswith('Tk'):
try:
pylab.all_figures
except AttributeError:
pylab.all_figures = []
figure_ori = pylab.figure
close_ori = pylab.close
# hack: sentinel to prevent pylab from destroying tk windows.
pylab.sentinel = 0
figure_ori(pylab.sentinel,figsize=(0.1, 0.1))
pylab.show()
pylab._pylab_helpers.Gcf.figs[pylab.sentinel].window.iconify()
def figure(num=None,*args,**kw):
"""Wrapper around pylab.figure which updates a global list of held figures."""
#print 'our figure:',num
if num == pylab.sentinel:
raise ValueError, \
'%s is an internal sentinel, do not use for your figures' % num
newfig = figure_ori(num,*args,**kw)
pylab.all_figures.append(newfig)
return newfig
def close(*args):
"""Close all open figures managed by our figure() wrapper."""
#print 'our close:',args
if len(args)==1 and args[0]=='all':
#print 'Closing figures:',pylab.all_figures
map(close_ori,pylab.all_figures)
pylab.all_figures = []
else:
close_ori(*args)
# overwrite the figure/close calls in matplotlib itself
pylab.figure = figure
pylab.close = close
del HACK_TK
# /HACK
##############################################################
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.