Generating charts in a loop

You have to be a little careful here -- remember whenever you are
creating plots in a loop you should pair every figure command with a
close to avoid memory leaks

for i in somerange:
    figure(1)
    scatter(mydata, ...)
    savefig(myfile)
    close(1)

You have a few other alternatives.... The hold state affects whether
new plot commands to an Axes/Subplot will overwrite the existing one
or add on to it

  scatter(mydata, ..., hold=False) # clear the existing axes
  scatter(mydata, ..., hold=True) # add to the existing axes

See also the commands clf (clear current figure) and cla (clear
current axes)

JDH

···

On Wed, 15 Mar 2006, Imara Jarrett wrote:

    >> I would like to generate matplotlib scatter plots in a python
    >> 'for' loop.

    > Use 'figure'.

Thanks!

By pairing every figure command with a close, I avoid memory leaks and solve my problem.

···

On 3/15/06, John Hunter < jdhunter@…4…> wrote:

“Alan” == Alan Isaac <
aisaac@…310…> writes:

> On Wed, 15 Mar 2006, Imara Jarrett wrote:
>> I would like to generate matplotlib scatter plots in a python
>> 'for' loop.


> Use 'figure'.

You have to be a little careful here – remember whenever you are
creating plots in a loop you should pair every figure command with a
close to avoid memory leaks

for i in somerange:

figure(1)
scatter(mydata, ...)
savefig(myfile)
close(1)

You have a few other alternatives… The hold state affects whether
new plot commands to an Axes/Subplot will overwrite the existing one

or add on to it

scatter(mydata, …, hold=False) # clear the existing axes
scatter(mydata, …, hold=True) # add to the existing axes

See also the commands clf (clear current figure) and cla (clear

current axes)

JDH


This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast

and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642


Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users