Return images with matplotlib?

Joshua J. Kugler joshua at eeinternet.com
Tue Feb 6 22:33:50 EST 2007


Jan Danielsson wrote:

> Hello all,
> 
>    I have written a program which takes some data from a postgresql
> database, and via mod_python outputs it as tables on a web site. Now I
> would like to present these tables as graphs, which matplotlib can do.
>   But in order to properly display these graphs on the web page, I need
> to return the image data, like so:
> 
> def barchart(req, params):
>    some_format = matplotlib.generate_fancy_graph(params)
>    png_buf = make_png_buffer(some_format)
>    return png_buf
> 
>    Is this possible? If so -- how?

If you are returning the buffer (and nothing else) directly to a browser you
can't print a Content-type header that says it's a png file, and the
browser will accept it as a graphic, as long as you call the script from
within an IMG tag.

j

-- 
Joshua Kugler
Lead System Admin -- Senior Programmer
http://www.eeinternet.com
PGP Key: http://pgp.mit.edu/  ID 0xDB26D7CE

-- 
Posted via a free Usenet account from http://www.teranews.com




More information about the Python-list mailing list