memory error with matplot

Discussion in 'Python' started by lisa.engblom@gmail.com, Dec 5, 2006.

  1. Guest

    Hi,

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

    #create and save the figure
    def CreateFigure(state, facility, unit, SO2, increment, year, P99):
    size = len(SO2)

    #Create Plot
    figure(1, figsize=(10,8))
    bar(range(1, size+2), SO2, width=0.1, color='k')
    grid(True)
    xlim(0,size)
    ylim(0, 1.1*SO2[-1])
    ylabel('SO2 [lb/hr]')
    heading = ConstructFigName(state, facility, unit, increment, year)
    title(heading)

    #set handles
    xticklines = getp(gca(), 'xticklines')
    xgridlines = getp(gca(), 'xgridlines')
    xticklabels = getp(gca(), 'xticklabels')
    yticklines = getp(gca(), 'yticklines')

    #set properties
    setp(xticklines, visible=False)
    setp(xgridlines, visible=False)
    setp(xticklabels, visible=False)
    setp(yticklines, visible=False)

    axhspan(P99, P99, lw=3, ec='r', fc='r')
    ax = gca()
    #P99 = str(P99)
    P99 = '%0.1f' % P99
    text(0.01, 0.95, '99th Percentile: '+P99+' lb/hr',
    transform=ax.transAxes)

    figpath = ConstructFigPath(state, facility, unit, increment, year)
    savefig(figpath)
    close()

    Can you see the problem?

    thanks,
    -Lisa
     
    , Dec 5, 2006
    #1
    1. Advertising

  2. John Hunter Guest

    >>>>> "lisa" == lisa engblom <> 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
     
    John Hunter, Dec 7, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mahesh Prasad
    Replies:
    1
    Views:
    738
    Tom Wells
    Feb 22, 2004
  2. Cy Huckaba
    Replies:
    1
    Views:
    1,176
    Xie Xiao
    Jun 26, 2003
  3. Julián Sanz García

    RAM Memory or virual memory

    Julián Sanz García, Nov 12, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    918
    Julián Sanz García
    Nov 12, 2004
  4. dug

    Choices: scipy, matplot ...

    dug, Feb 19, 2007, in forum: Python
    Replies:
    1
    Views:
    330
    sturlamolden
    Feb 19, 2007
  5. Todd
    Replies:
    4
    Views:
    567
    Jeff Higgins
    Sep 5, 2007
Loading...

Share This Page