Hello! I'm dynamically dishing out plots via matplotlib through a web server, so I really want to savefig to some type of memory object.
Using both os.pipe and cStringIO objects, I get this type of error: In [9]:%history 1 : import matplotlib 2 : matplotlib.use('Agg') 3 : import pylab 4 : ax = pylab.gca() 5 : ax.specgram( range(100) ) 6 : import cStringIO 7 : sbuf = cStringIO.StringIO() 8 : pylab.savefig( sbuf, format='png' ) In [8]:pylab.savefig( sbuf, format='png' ) --------------------------------------------------------------------------- exceptions.TypeError Traceback (most recent call last) /home/gmabey/src/R9619_zippy/Projects/R9619_NChannelDetection/AcqLibWeb/<ipython console> /usr/local/stow/matplotlib-0.87.7/lib/python2.4/site-packages/matplotlib/pylab.py in savefig(*args, **kwargs) 811 def savefig(*args, **kwargs): 812 fig = gcf() --> 813 return fig.savefig(*args, **kwargs) 814 if Figure.savefig.__doc__ is not None: 815 savefig.__doc__ = _shift_string(Figure.savefig.__doc__) /usr/local/stow/matplotlib-0.87.7/lib/python2.4/site-packages/matplotlib/figure.py in savefig(self, *args, **kwargs) 680 kwargs[key] = rcParams['savefig.%s'%key] 681 --> 682 self.canvas.print_figure(*args, **kwargs) 683 684 def colorbar(self, mappable, cax=None, **kw): /usr/local/stow/matplotlib-0.87.7/lib/python2.4/site-packages/matplotlib/backends/backend_agg.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, **kwargs) 458 if not is_string_like(filename): 459 # assume png and write to fileobject --> 460 self.renderer._renderer.write_png(filename) 461 #pass 462 else: TypeError: Could not convert object to file pointer > /usr/local/stow/matplotlib-0.87.7/lib/python2.4/site-packages/matplotlib/backends/backend_agg.py(460)print_figure() 459 # assume png and write to fileobject --> 460 self.renderer._renderer.write_png(filename) 461 #pass I'm a bit confused as to where the exception is actually getting raised. I suppose the renderer's write_png method must be in C? I implemented a tempfile solution, but I'm surprised that the cStringIO doesn't already work. <fellowsophical_question> Should it? </fellowsophical_question> Thanks, Glen ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users