Return images with matplotlib?

J

Jan Danielsson

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?

--
Kind regards,
Jan Danielsson
------------ And now a word from our sponsor ------------------
For a quality usenet news server, try DNEWS, easy to install,
fast, efficient and reliable. For home servers or carrier class
installations with millions of users it will allow you to grow!
---- See http://netwinsite.com/sponsor/sponsor_dnews.htm ----
 
J

Joshua J. Kugler

Jan said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top