How to close a figure ?

leau2001 wrote:

    >> I made some figure in a loop and i want to close after the
    >> figure show.

    > Not absolutely sure what you mean, but to produce some
    > plots and save them in a loop I do

    > f = figure() for i in range(..): plot(...) savefig(...)
    > f.clf() # clear figure for re-use close(f)

Often times what people are looking for is they want to the figure to
pop up on the screen, look at it, have it close, and move on. One way
to achieve this is to run mpl in interactive mode

and then insert a time.sleep or call

  input("Press any key for next figure: ")

If this is what you are doing, threading becomes important. This is
discussed on the web page linked above, and your best bet is to either
use the tkagg backend or better yet, use ipython in -pylab mode.

Something like

import sys
from pylab import figure, close, show, nx, ion


while 1:
    fig = figure()
    ax = fig.add_subplot(111)
    x, y = nx.mlab.rand(2,30)
    k = raw_input("press any key to continue, q to quit: ")
    if k.lower().startswith('q'):