John Hunter wrote:
"Sascha" == Sascha <saschagl@...159...> writes:
> I am writing a web server app that creates charts among
> other things. I am trying to get rid of the temporary file
> that I use to transmit the figures created with matplotlib
> to the actual web server. Although print_figure says "If
> filename is a fileobject, write png to file object (thus
> you can, for example, write the png to stdout)" I can't
> successfully write anything to stdout. Anyone knows an
> example or can give me some hint what I can do to get rid
> of the tempfile?
Short answer: no known way to do this currently, though we'd like to
figure it out. As far as I know (and could very well be wrong)
libpng requires a FILE*, which StringIO and cStringIO do not provide.
StringIO isn't the issue here; being able to write to sys.stdout, which
ought to have a valid FILE* underneath, is the issue.
Why not use PIL where it's available? backend_agg2.py has a start at
this. Here's a slightly more fleshed-out (but untested) implementation
for backend_agg.py :
if not is_string_like(filename):
have_pil = True
have_pil = False
img = Image.frombuffer('RGBA', (self.width, self.height),
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter