pylab.close() gtk error. Could be a bug (?)

2006/2/24, David Huard <david.huard@…287…
:

What if I want it to be non-interactive ? I want to save graphics

directly to a file from a script, without them being displayed. It’s

weird that in this case close() crashes the whole thing.

Yes your wright the script have to work in non interactive mode. (I was just trying to give an explanation to Emmanuel problem).

The following script should work (but it crashes like Emmanuel reported):

#!/usr/bin/python

import matplotlib

import pylab

#Turn off interactive mode

matplotlib.interactive(False)

#plot figure 1

pylab.figure()

pylab.plot([1,2,3],[1,2,3])

pylab.savefig(“test_pylab1.png”)

pylab.close()

#plot figure 2

pylab.figure()

pylab.plot([1,2,3],[1,2,3])

pylab.savefig(“test_pylab2.png”)

pylab.close()

Second figure cannot be created due to the crash.

We need the help of matplotlib Gurus !

Regards,

David

2006/2/24, David Huard <david.huard@…287…>:

···

What if I want it to be non-interactive ? I want to save graphics
directly to a file from a script, without them being displayed. It’s
weird that in this case close() crashes the whole thing.

David

2006/2/23, David TREMOUILLES <
david.trem@…287…>:

Could that be because interactive mode was set in your previous install ?

(in .matplotlibrc file)
if I try:

#!/usr/bin/python

import matplotlib
import pylab
matplotlib.interactive(True)
pylab.figure()
pylab.close()

Then it works…
Hope this could help you…

David

2006/2/23, Emmanuel Pecontal <pecontal@…419…>:

Hello,

If I run the following script on my system (SuSE 10.0, matplotlib-0.87 but
same behaviour with 0.86):

#!/usr/bin/python

import matplotlib
import pylab

pylab.figure()

pylab.close ()

It crashes with the following error message:

Traceback (most recent call last):
File “./tmp.py”, line 8, in ?
pylab.close()
File
“/usr/lib/python2.4/site-packages/matplotlib/pylab.py”,
line 768, in
close
else: _pylab_helpers.Gcf.destroy(figManager.num)
File

“/usr/lib/python2.4/site-packages/matplotlib/_pylab_helpers.py”,
line

28, in destroy
figManager.destroy()
File
“/usr/lib/python2.4/site-packages/matplotlib/backends/backend_gtk.py”,

line 456, in destroy
gtk.main_quit()
RuntimeError: called outside of a mainloop

Does someone has an idea of the problem?
I didn’t have this kind of problem with my SuSE 9.3 and matplotlib-0.85


Emmanuel Pécontal

CRAL - Observatoire de Lyon
9, Av. Charles Andre
F-69561 Saint Genis Laval Cedex

tel (33) (0)4.78.86.83.76 - fax (33) (0)4.78.86.83.86

email : pecontal@…120…419…

Hi,

What one can do is :

f = figure(1)
... some figure
f.clear()

f = figure(1)
... another figure
f.clear()

However, it is only a work around, not an actual solution...

Cheers,

David

2006/2/24, David TREMOUILLES <david.trem@...287...>:

···

   >>2006/2/24, David Huard <david.huard@...287... >:
    >>What if I want it to be non-interactive ? I want to save graphics
    >>directly to a file from a script, without them being displayed. It's
    >>weird that in this case close() crashes the whole thing.

Yes your wright the script have to work in non interactive mode. (I was
just trying to give an explanation to Emmanuel problem).
The following script should work (but it crashes like Emmanuel reported):

#!/usr/bin/python
import matplotlib
import pylab
#Turn off interactive mode
matplotlib.interactive(False)
#plot figure 1
pylab.figure()
pylab.plot([1,2,3],[1,2,3])
pylab.savefig("test_pylab1.png")
pylab.close()
#plot figure 2
pylab.figure()
pylab.plot([1,2,3],[1,2,3])
pylab.savefig("test_pylab2.png")
pylab.close()

Second figure cannot be created due to the crash.

We need the help of matplotlib Gurus !

Regards,

David

2006/2/24, David Huard <david.huard@...287...>:
> What if I want it to be non-interactive ? I want to save graphics
> directly to a file from a script, without them being displayed. It's
> weird that in this case close() crashes the whole thing.
>
> David
>
> 2006/2/23, David TREMOUILLES < david.trem@...287...>:
> > Could that be because interactive mode was set in your previous install
?
> > (in .matplotlibrc file)
> > if I try:
> >
> > #!/usr/bin/python
> > import matplotlib
> > import pylab
> > matplotlib.interactive(True)
> > pylab.figure()
> > pylab.close()
> >
> > Then it works...
> > Hope this could help you...
> >
> > David
> >
> > 2006/2/23, Emmanuel Pecontal <pecontal@...419...>:
> >
> > > Hello,
> > >
> > > If I run the following script on my system (SuSE 10.0, matplotlib-0.87
but
> > > same behaviour with 0.86):
> > >
> > > #!/usr/bin/python
> > >
> > > import matplotlib
> > > import pylab
> > >
> > > pylab.figure()
> > > pylab.close ()
> > >
> > > It crashes with the following error message:
> > >
> > > Traceback (most recent call last):
> > > File "./tmp.py", line 8, in ?
> > > pylab.close()
> > > File
> > "/usr/lib/python2.4/site-packages/matplotlib/pylab.py",
> > line 768, in
> > > close
> > > else: _pylab_helpers.Gcf.destroy(figManager.num)
> > > File
> >
"/usr/lib/python2.4/site-packages/matplotlib/_pylab_helpers.py",
> > line
> > > 28, in destroy
> > > figManager.destroy()
> > > File
> >
"/usr/lib/python2.4/site-packages/matplotlib/backends/backend_gtk.py",
> > > line 456, in destroy
> > > gtk.main_quit()
> > > RuntimeError: called outside of a mainloop
> > >
> > > Does someone has an idea of the problem?
> > > I didn't have this kind of problem with my SuSE 9.3 and
matplotlib-0.85
> > >
> > > --
> > > Emmanuel Pécontal
> > >
> > > CRAL - Observatoire de Lyon
> > > 9, Av. Charles Andre
> > > F-69561 Saint Genis Laval Cedex
> > >
> > > tel (33) (0)4.78.86.83.76 - fax (33) (0)4.78.86.83.86
> > >
> > > email : pecontal@...419...
> > >
> >
> >
>

Hi David,

I was in non interactive mode. But I finally solved the problem by replacing
the GTKAgg backend by the TkAgg one. I don't understand why the GTKAgg does
not work, but well... if the TkAgg does...

Emmanuel

···

Le Vendredi 24 Février 2006 16:47, David TREMOUILLES a écrit :

   >>2006/2/24, David Huard <david.huard@...287... >:
   >>What if I want it to be non-interactive ? I want to save graphics
   >>directly to a file from a script, without them being displayed. It's
   >>weird that in this case close() crashes the whole thing.

Yes your wright the script have to work in non interactive mode. (I was
just trying to give an explanation to Emmanuel problem).
The following script should work (but it crashes like Emmanuel reported):

#!/usr/bin/python
import matplotlib
import pylab
#Turn off interactive mode
matplotlib.interactive(False)
#plot figure 1
pylab.figure()
pylab.plot([1,2,3],[1,2,3])
pylab.savefig("test_pylab1.png")
pylab.close()
#plot figure 2
pylab.figure()
pylab.plot([1,2,3],[1,2,3])
pylab.savefig("test_pylab2.png")
pylab.close()

Second figure cannot be created due to the crash.

We need the help of matplotlib Gurus !

Regards,

David

2006/2/24, David Huard <david.huard@...287...>:
> What if I want it to be non-interactive ? I want to save graphics
> directly to a file from a script, without them being displayed. It's
> weird that in this case close() crashes the whole thing.
>
> David
>
> 2006/2/23, David TREMOUILLES < david.trem@...287...>:
> > Could that be because interactive mode was set in your previous install
>
> ?
>
> > (in .matplotlibrc file)
> > if I try:
> >
> > #!/usr/bin/python
> > import matplotlib
> > import pylab
> > matplotlib.interactive(True)
> > pylab.figure()
> > pylab.close()
> >
> > Then it works...
> > Hope this could help you...
> >
> > David
> >
> > 2006/2/23, Emmanuel Pecontal <pecontal@...419...>:
> > > Hello,
> > >
> > > If I run the following script on my system (SuSE 10.0,
> > > matplotlib-0.87but same behaviour with 0.86):
> > >
> > > #!/usr/bin/python
> > >
> > > import matplotlib
> > > import pylab
> > >
> > > pylab.figure()
> > > pylab.close ()
> > >
> > > It crashes with the following error message:
> > >
> > > Traceback (most recent call last):
> > > File "./tmp.py", line 8, in ?
> > > pylab.close()
> > > File
> >
> > "/usr/lib/python2.4/site-packages/matplotlib/pylab.py",
> > line 768, in
> >
> > > close
> > > else: _pylab_helpers.Gcf.destroy(figManager.num)
> > > File
> >
> > "/usr/lib/python2.4/site-packages/matplotlib/_pylab_helpers.py",
> > line
> >
> > > 28, in destroy
> > > figManager.destroy()
> > > File
> >
> > "/usr/lib/python2.4/site-packages/matplotlib/backends/backend_gtk.py",
> >
> > > line 456, in destroy
> > > gtk.main_quit()
> > > RuntimeError: called outside of a mainloop
> > >
> > > Does someone has an idea of the problem?
> > > I didn't have this kind of problem with my SuSE 9.3 and
>
> matplotlib-0.85
>
> > > --
> > > Emmanuel Pécontal
> > >
> > > CRAL - Observatoire de Lyon
> > > 9, Av. Charles Andre
> > > F-69561 Saint Genis Laval Cedex
> > >
> > > tel (33) (0)4.78.86.83.76 - fax (33) (0)4.78.86.83.86
> > >
> > > email : pecontal@...419...

--
Emmanuel Pécontal

CRAL - Observatoire de Lyon
9, Av. Charles Andre
F-69561 Saint Genis Laval Cedex

tel (33) (0)4.78.86.83.76 - fax (33) (0)4.78.86.83.86

email : pecontal@...419...
~