|
From: Christopher F. <ch...@fo...> - 2003-12-15 20:22:48
|
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
try:
figure(1)
nbins = min(nbins or 10,len(unique(data)))
'Generate histogram'
hist(data,nbins)
'Plot options'
xlabel(name)
ylabel("Frequency")
show()
'Save to file'
savefig("%s%s.png" % (name,suffix))
close(1)
except OverflowError:
print '... cannot generate histogram'
else:
'... otherwise, plot recursively'
tdata = swapaxes(data,0,1)
for i in range(len(tdata)):
Thanks for any advice,
C.
--
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
|