[SciPy-user] gplt problems: saving output to file

Christopher Fonnesbeck chris at fonnesbeck.org
Wed May 5 09:47:23 CDT 2004


I continue to have a problem saving the output from certain gplt calls  
to disk. I have two plotting routines, both which call gplt.plot, one  
which plots a histogram, and the other which plots a time series.  
Though both produce output properly to screen as expected, the latter  
produces a zero-length file. Here are the two methods:

     def  
histogram(self,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:
                 'Generate reasonable bins if none specified'
                 if not nbins: nbins = 50 * (len(data)>1000) or 10
                 'Generate binned values'
                 counts,lowval,width,extra =  
histogram(data,numbins=nbins)
                 'Generate x-axis values'
                 values = [lowval]
                 for i in range(nbins-1):
                     values.append(values[-1]+width)
                 'Pass to plotting function'
                 plot(values,counts)
                 'Plot options'
                 grid('off')
                 xtitle(name)
                 ytitle("Frequency")
                 'Save to file'
                 output("%s%s.png" % (name,suffix),'png')
                 close()
             except OverflowError:
                 print '... cannot generate histogram'
         else:
             '... otherwise, plot recursively'
             tdata = swapaxes(data,0,1)
             for i in range(len(tdata)):
                  
self.histogram(tdata[i],name+'_'+str(i),nbins=nbins,xlab=xlab,suffix=suf 
fix)

     def time_series(self,data,name,xlab='Time',ylab='State',suffix=''):
         'Plot (mutiple) time series'

         plot(data)
         print 'Plotting',name
         grid('off')
         xtitle(xlab)
         ytitle(ylab)
         output("%s%s.png" % (name,suffix),'png')
         close()


I dont see any obvious reason why output() would produce different  
results for these two methods. If anyone has a plausible explanation  
for what may be happening, I'd love to hear from them.

Thanks,
Chris

PS -- this occurs on both Linux and OSX

--
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

"I don't remember any kind of heaviness ruining my time at Yale."
          George W. Bush, on the civil rights movement
--
Putting http://wecanstopspam.org in your email helps it pass through  
overzealous spam filters. 



More information about the SciPy-user mailing list