On 05/22/2011 07:04 AM, Mike Kaufman wrote:
> Hi,
>
> After switching over from the MacOSX backend to the GTKAgg backend, I
> started notice a big change in drawing behavior.
>
> Now I know that MacOSX is interactive all the time by [mis]design, so I
> wasn't surprised that I would have to add draw() commands when
> isinteractive()==False; however, when using the non-pyplot commands,
> i.e. ax.plot() rather than plot(), I must use draw() to render the new
> Line2D even when isinteractive()==True. This doesn't seem correct
> behavior to me. A lot of drawing just can't be done by the pyplot
> functions. You have to go to the axes functions.
This is inherent in the design. Pyplot functions are wrappers that do
two things: call Axes methods on the current axes, and then call
draw_if_interactive(). The rationale is that even when working
interactively, one doesn't necessarily want to draw immediately every
time a new Artist is created. So yes, working interactively with the OO
interface requires frequent plt.draw() invocations, making it only
semi-interactive.
>
> On another, but related topic, I use ipython -pylab, and generally
> develop by using the `run -i file.py` syntax. I have found what I think
> is a bug where if I have a file that consists of:
>
> cat>> file.py<<EOF
> print isinteractive()
> EOF
>
> and I do
>
> In [1]: isinteractive()
> Out[1]: True
> In [2]: run -i file.py
> False
>
> which means I either have to do ion() or draw() each time even for
> pyplot commands. Is this a bug in ipython or matplotlib?
I think it is inherent in the -pylab mode of ipython, which is designed
to run a script as if it were being run directly from the command line.
To do that, it turns interactive mode off before running the script, and
restores interactive mode to its original value afterwards. A script
intended to produce a screen plot includes a show() command. Running
such a script with ipython -pylab then leaves one or more plots with
which one can interact directly or via the ipython command line--but in
the latter case, if pyplot functions are not used, then draw() must be
used for a redraw.
If you want the contents of the file to be executed exactly as if you
had typed them in at the ipython command line, you can use the built-in
execfile() function instead of the ipython %run magic.
The ipython %edit magic can also be used for this.
Eric
>
> M
>