From: David T. <dav...@gm...> - 2006-02-24 15:47:27
|
>>2006/2/24, David Huard <dav...@gm... >: >>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 jus= t 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 <dav...@gm...>: > > 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 < dav...@gm...>: > > 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 <pec...@ob...>: > > > > > Hello, > > > > > > If I run the following script on my system (SuSE 10.0, matplotlib-0.8= 7but > > > 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=E9contal > > > > > > 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 : pec...@ob... > > > > > > > > |
From: David H. <dav...@gm...> - 2006-02-24 19:24:26
|
Hi, What one can do is : f =3D figure(1) ... some figure f.clear() f =3D figure(1) ... another figure f.clear() However, it is only a work around, not an actual solution... Cheers, David 2006/2/24, David TREMOUILLES <dav...@gm...>: > > >>2006/2/24, David Huard <dav...@gm... >: > >>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 <dav...@gm...>: > > 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 < dav...@gm...>: > > > Could that be because interactive mode was set in your previous insta= ll > ? > > > (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 <pec...@ob...>: > > > > > > > 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=E9contal > > > > > > > > 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 : pec...@ob... > > > > > > > > > > > > > > |
From: John H. <jdh...@ac...> - 2006-02-24 20:06:54
|
>>>>> "David" == David TREMOUILLES <dav...@gm...> writes: >>> 2006/2/24, David Huard <dav...@gm... >: 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> Yes your wright the script have to work in non interactive David> mode. (I was just trying to give an explanation to Emmanuel David> problem). The following script should work (but it crashes David> like Emmanuel reported): David> #!/usr/bin/python import matplotlib import pylab #Turn off David> interactive mode matplotlib.interactive(False) #plot figure David> 1 pylab.figure() pylab.plot([1,2,3],[1,2,3]) David> pylab.savefig("test_pylab1.png") pylab.close() #plot figure David> 2 pylab.figure() pylab.plot([1,2,3],[1,2,3]) David> pylab.savefig("test_pylab2.png") pylab.close() This is a bug and I fixed it in CVS (Steve take a look and see if you agree with the show._mainloop approach) but basically you don't want to use matplotlib this way. If you do not want the figure to pop-up, that is you only want to create a PNG and move on, just use the Agg backend rather than GTK*. Eg python myscript.py -dAgg The problem you experienced arose because you closed all the figures before you called show in non-interactive mode. For a GUI this makes no sense, because you are telling the GUI to close all the windows before it shows any of them. I fixed the GTK backend to not try and quit gtk before starting it :-) In summary, I recommend: * in non-interactive mode with a GUI backend, always end your script with show. This starts the GUI mainloop. Do not close all your figures before you call show. * if you don't want an image to pop up, use non-interactive mode, and a non-GUI backend, and show is not required but it doesn't hurt either. JDH |
From: Emmanuel P. <pec...@ob...> - 2006-02-25 16:45:17
|
Hi David, I was in non interactive mode. But I finally solved the problem by replacin= g=20 the GTKAgg backend by the TkAgg one. I don't understand why the GTKAgg does= =20 not work, but well... if the TkAgg does... Emmanuel Le Vendredi 24 F=C3=A9vrier 2006 16:47, David TREMOUILLES a =C3=A9crit=C2= =A0: > >>2006/2/24, David Huard <dav...@gm... >: > >>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 <dav...@gm...>: > > 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 < dav...@gm...>: > > > Could that be because interactive mode was set in your previous insta= ll > > > > ? > > > > > (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 <pec...@ob...>: > > > > 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=C3=A9contal > > > > > > > > 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 : pec...@ob... =2D-=20 Emmanuel P=C3=A9contal CRAL - Observatoire de Lyon 9, Av. Charles Andre =46-69561 Saint Genis Laval Cedex tel (33) (0)4.78.86.83.76 - fax (33) (0)4.78.86.83.86 email : pec...@ob... ~ |