"batch" plots

First off, I want to congratulate the authors of matplotlib for making a great package. This is the python plotting library I've been waiting for.

I'm trying to use matplotlib on OSX (so with WX rather than gtk) in conjunction with my own code that produces Markov chain Monte Carlo simulations. At the end of the simulation, I try to plot traces and histograms of all of the sampled values. However, matplotlib gets stuck on the first plot. After calling show(), it does not move to the next line of code for some reason, but instead hangs. When I try and close the plot manually, it terminates the python code. How can I get matplotlib to produce a new plot each time it is called, moving on after each plot is produced, displayed and saved to file. Here is a sample function from my code:

def plot_histogram(data,name,nbins=None,xlab='Value',ylab='Frequency',suffix=''):
  'Internal histogram specification for handling nested arrays'
  'If there is only one data array, go ahead and plot it ... '
  if len(shape(data))==1:
    print 'Generating histogram of',name
      nbins = min(nbins or 10,len(unique(data)))
      'Generate histogram'
      'Plot options'
      'Save to file'
      savefig("%s%s.png" % (name,suffix))
    except OverflowError:
      print '... cannot generate histogram'
    '... otherwise, plot recursively'
    tdata = swapaxes(data,0,1)
    for i in range(len(tdata)):

Thanks for any advice,


Christopher J. Fonnesbeck ( c h r i s @ f o n n e s b e c k . o r g )
Georgia Cooperative Fish & Wildlife Research Unit, University of Georgia