plot windows

Hello,

I want to save a large number of figures to file, roughly like this:

import pylab
for i in xrange(100):
     pylab.plot(x[i], y[i])
     pylab.savefig('plot' + str(i) + '.eps')
     pylab.figure()

However, a large number of figure windows show up on screen, and eventually, the application runs out of memory and crashes. How do I avoid these windows?

Regards,
Paul.

Paul Anton Letnes wrote:

Hello,

I want to save a large number of figures to file, roughly like this:

import pylab
for i in xrange(100):
     pylab.plot(x[i], y[i])
     pylab.savefig('plot' + str(i) + '.eps')
     pylab.figure()

However, a large number of figure windows show up on screen, and eventually, the application runs out of memory and crashes. How do I avoid these windows?

Replace the pylab.figure() command with pylab.clf(), or with pylab.close().

Eric

···

Regards,
Paul.

Thanks, this helps a lot. Is it possible to completely eliminate the windows popping up? Though not very important, it is still annoying that windows pop up when running a script in the background.

Paul.

···

On 24. feb.. 2009, at 08.11, Eric Firing wrote:

Paul Anton Letnes wrote:

Hello,
I want to save a large number of figures to file, roughly like this:
import pylab
for i in xrange(100):
    pylab.plot(x[i], y[i])
    pylab.savefig('plot' + str(i) + '.eps')
    pylab.figure()
However, a large number of figure windows show up on screen, and eventually, the application runs out of memory and crashes. How do I avoid these windows?

Replace the pylab.figure() command with pylab.clf(), or with pylab.close().

Eric

Regards,
Paul.

Hello Paul Anton,

Is it possible to completely eliminate the
windows popping up? Though not very important, it is still annoying

You may want to choose another backend. That is e.g. "agg" backend, that
doesn't use a X-window. Something like the following should give what you
need:

----------------------------------

import matplotlib
matplotlib.use("Agg")
# Please notice: Backend must be chosen before importing pylab
import pylab

pylab.plot( ... )

-----------------------------------

regards Matthias

PS: some more information copied from the online docu:

http://matplotlib.sourceforge.net/api/matplotlib_configuration_api.html?highlight=use#matplotlib.use

matplotlib.use(arg, warn=True)

    Set the matplotlib backend to one of the known backends.

    The argument is case-insensitive. For the Cairo backend, the argument can
have an extension to indicate the type of output. Example:

        use(‘cairo.pdf’)

    will specify a default of pdf output generated by Cairo.

    Note: this function must be called before importing pylab for the first
time; or, if you are not using pylab, it must be called before importing
matplotlib.backends. If warn is True, a warning is issued if you try and
callthis after pylab or pyplot have been loaded. In certain black magic use
cases, eg pyplot.switch_backends, we are doing the reloading necessary to
make the backend switch work (in some cases, eg pure image backends) so one
can set warn=False to supporess the warnings

···

On Tuesday 24 February 2009 09:44:38 Paul Anton Letnes wrote:

Sounds like you are calling `show`.
Don't.

Cheers,
Alan Isaac

···

On 2/24/2009 3:44 AM Paul Anton Letnes apparently wrote:

Is it possible to completely eliminate the windows popping up? Though not very important, it is still annoying that windows pop up when running a script in the background.