From: John H. <jdh...@ac...> - 2006-02-24 20:06:55
|
>>>>> "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 |