[Tutor] Closing a matplotlib window after show()

Wayne Watson sierra_mtnview at sbcglobal.net
Mon Feb 8 05:11:16 CET 2010


The code below is a typical example of matplotlib use. I've used it both 
in xp and win7 in IDLE. It produces the required plos and stop with the 
plot display. If I close the plot window with the x in the upper right 
corner,  the shell window is left open. I have to do the same to close 
it. If I run it again, and look at the shell window, it looks hung up 
with the cursor below the >>> prompt. Ctrl-c doesn't break it, and I 
have to resort to x again. There must be some mechanism to insert below 
that allows the program to continue on and thus complete. Supposedly 
fig.close() will but I've  put it in several places and have gotten 
unknown attribute to figure.
Comments?

================
from matplotlib.pyplot import figure, show
from numpy import arange, pi, cos, sin, pi
from numpy.random import rand

# unit area ellipse
rx, ry = 3., 1.
area = rx * ry * pi
theta = arange(0, 2*pi+0.01, 0.1)
verts = zip(rx/area*cos(theta), ry/area*sin(theta))

x,y,s,c = rand(4, 30)
s*= 10**2.

fig = figure()
ax = fig.add_subplot(111)
ax.scatter(x,y,s,c,marker=None,verts =verts)

show()




-- 
My life in two words. "Interrupted Projects." -- WTW (quote originator)


More information about the Tutor mailing list