memory error with matplot

John Hunter jdhunter at ace.bsd.uchicago.edu
Thu Dec 7 16:45:41 EST 2006


>>>>> "lisa" == lisa engblom <lisa.engblom at gmail.com> writes:

    lisa> Hi, I am using matplotlib with python to generate a bunch of
    lisa> charts.  My code works fine for a single iteration, which
    lisa> creates and saves 4 different charts.  The trouble is that
    lisa> when I try to run it for the entire set (about 200 items) it
    lisa> can run for 12 items at a time.  On the 13th, I get an error
    lisa> from matplotlib that says it can't access data.  However, if
    lisa> I start the program at the point it failed before it works
    lisa> fine and will create the charts for the next 12 before
    lisa> failing.  I assume that I am not closing the files properly
    lisa> somehow or otherwise misallocating memory.  I tried just
    lisa> reimporting pylab each iteration, but that didn't help.
    lisa> This is the function that creates a chart:

There are a couple of things to try.  First, on a long shot, does it
help to do

  close(1)

instead if simply close().  I don't think it will but worth a try.

Second, I think there is a small leak in the tkcanvas, but not in
matplotlib proper.  Do you need to display the graphs you are
creating, or do you merely want to save them?  If the latter, simply
use the Agg backend 

import matplotlib
matplotlib.use('Agg')

*before* you import pylab.

Finally, if you are still having troubles, post a complete,
free-standing, script to the matplotlib mailing list and we'll see if
we can replicate it.

You may also want to take a look at the FAQ on memory leaks:

http://matplotlib.sourceforge.net/faq.html#LEAKS

JDH



More information about the Python-list mailing list