[CentralOH] GUI Tools Survey

Eric Floehr eric at intellovations.com
Wed Aug 11 15:53:31 CEST 2010


The book "Matplotlib for Python Developers" has an entire chapter on
embedding Matplotlib output (or generating it in realtime) on the web, using
a number of different frameworks:

1. CGI (via Apache's mod_cgi)
2. mod_python
3. Django
4. Pylons

For Django (as that's what I'm familiar with) in your view code you use
matplotlib.backends.backend_agg.FigureCanvasAgg as your canvas you plot the
Figure on.  Then instead of rendering a template response, you create an
HttpResponse with content_type 'image/png' (or any of the types FigureCanvas
supports) and print the bits to the response (the FigureCanvas takes a "file
like" object or a string filename, and HttpResponse is a file-like object
(i.e. has a write method)), like:

fig = Figure()
canvas = FigureCanvasAgg(fig)

... do your plot stuff ...

response = django.http.HttpResonse(content_type='image/png')
canvas.print_png(response)

Only the last two lines are specific to the web framework, everything else
is generic plot generation that can be used in a regular GUI, etc.

So whatever URL you have defined for the image, it will return the png.

-Eric


On Wed, Aug 11, 2010 at 9:26 AM, James - Atlantix <james at atlantixeng.com>wrote:

> The survey is a great idea, and hopefully will provide some very useful
> feedback. My main concern about Web based GUI's is the ability to add rich
> math content to them, such as with Matplotlib output. Has anyone any
> experience in this?
>
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> http://mail.python.org/mailman/listinfo/centraloh
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/mailman/private/centraloh/attachments/20100811/b159b5d5/attachment.html>


More information about the CentralOH mailing list