From: John H. <jdh...@ac...> - 2005-02-01 20:39:20
|
>>>>> "Fernando" == Fernando Perez <Fer...@co...> writes: Fernando> Hi all, I have a question: in interactive (ipython Fernando> -pylab) mode, a call to savefig('foo.eps') (either via Fernando> %run or straight at the prompt) still pops up a GUI plot Fernando> window. If I run the same script from a system command Fernando> line, the eps is made, but no GUI opens (what I consider Fernando> the correct behavior). Fernando> Is this something that should be fixed in ipython or in Fernando> matplotlib? For the sake of clarity, let's consider the canonical script import matplotlib matplotlib.use('PS') from pylab import * plot([1,2,3]) savefig('test.ps') show() When run from the shell, it does what you want -- makes a PS with no popup. It fails in ipython (pops up a window) because you have already selected a backend and all pylab commands are directed to that backend. How to fix it? * ipython invokes an external python process to run each script. Of course you pay a performance hit here, and this would likely change the meaning of the way run is meant to work (eg, are local ipython shell vars available in a "run" script. * provide better support for backend switching in matplotlib. Eg, allowing you at any time to call matplotlib.use. Currently, this only works before the import of pylab. It may be possible to write a pylab.use that simply rebinds the 4 backend functions: new_figure_manager, error_msg, draw_if_interactive, show. At the end of a "run", you could simply do a matplotlib.pylab.use(defaultBackend) to rebind. run could be enhanced to support backend switching run somescript.py -dPS much like one can do from the shell. You know more about python module reloading than I do. How does one force a module to reload, eg if I wanted to set the rc 'backend' param and then do, eg rcParams['backend'] = 'PS' from backends import new_figure_manager, error_msg, draw_if_interactive, show to get new symbols? There may be another way, but those two come to mind. I'll mull it over. Fernando> ps. Yes, John, I've finally started to use matplotlib Fernando> for my own work. Brace yourself, I'm compiling a pretty Fernando> hefty list of things to do. I hope you don't plan on Fernando> sleeping much in the coming months ;) Well, I knew it was coming.... Stress tests are usually a good thing. Plus, I'm sure you can't do anything to interrupt my sleep that my 3 kids haven't already mastered! JDH |