Matplotlib - an odd problem

koranthala koranthala at gmail.com
Wed Jun 24 14:38:02 EDT 2009


Hi,
I am using Matplotlib with Django to display charts on the web page.
I am facing an odd problem in that, everytime I do a refresh on the
web page, the image darkens - and the text becomes little unreadable.
5/6 refreshes later, the text becomes completely unreadable.
Since I am using Django test server, the same process is being used.
i.e. every refresh does not create a new process. When I tried killing
the process, the image again cleared.
So I think it is sort of memory leak or a saved value which is messing
up something.
But I cannot seem to find the issue at all.

The code is as follows -

import pylab
from cStringIO import StringIO

def print_pie_chart(request):
    labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
    data = [15,30,45, 10]
    pylab.figure(1, figsize=(2,2))
    ax = pylab.axes([0.1, 0.1, 0.8, 0.8])
    pylab.pie(data, explode=None, labels=labels, autopct='%1.1f%%',
shadow=True)
    out = StringIO()
    pylab.savefig(out, format="PNG")
    out.seek(0)
    response = HttpResponse()
    response['Content-Type'] = 'image/png'
    response.write(out.read())
    return response

Can anyone help me out here?



More information about the Python-list mailing list