Stop saying you want to avoid show(); (…). You probably *need* to use
show; with 1.0.1
The above was wrong--see below. If you start with interactive mode on, you do not need show at all. In non-interactive mode, you do need show.
in interactive mode, it will not block. Your script can close the
windows; your user doesn't have to do so manually.
You are right: your script shows that the latest (1.0.1) show() is great, as
it is non-blocking in interactive mode (except with the macosx backend).
(It is the pre-1.0.1 blocking show() that was not a solution.)
It sounds like you are indeed talking about a free-standing script, that
is, not involving ipython or other intermediate shell, correct?
Does the attached
script illustrate something roughly like what you are trying to do?
Yes, it does, thanks. Just a detail: since the interactive mode is on, the
plt.draw()s in the second part are not necessary, are they?
Not a detail: you do need the draw if you are not ending with a pyplot function, as opposed to an object method. You could just use the pyplot function, plt.plot(), instead of the method, ax.plot(), etc., which would call the draw automatically.
Now, you may find that everything works the same if you eliminate the first draw in my example; that is because the plt.figure() call has put a draw request in to the gui toolkit, and the toolkit is not executing it right away. Don't rely on this, however; if you are using the object methods, call draw when you want the figure to be refreshed.
So, to summarize, the latest 1.0.1 show() does the actual drawing (not
draw()), is non-blocking in interactive mode, and can be called multiple
times. This is both convenient (no need to manually close umpteen windows
one by one), and efficient (non interactive mode can be used up until show()
is called). Thus, the practical side of the problem is closed: thanks!
Not quite. Draw() ensures that everything is up to date; show() is not a direct substitute.
In my example script, I should have put the call to plt.ion() *before* all other pyplot calls. If you do that, then you actually don't need the show() at all, because the the initial call to plt.figure() in interactive mode displays the figure.
I have been asking these questions because I have been using and teaching
(Python and) Matplotlib for 3 years, now, to students who use a variety of
OSes, so I wanted to get things straight.
On the "theoretical" side, draw() is actually rarely used for drawing or
refreshing simple figures (including common non-animated figures), but is
more for "some more advanced features such as animations and widgets, as
well as for internal use.", as Ben was writing, right? And show() is really
the function that commonly does the actual display or refresh, right? If
this is correct, I will be done with my questions.
No, if you use object methods rather than the pyplot interface, then you need to use draw(). For example, if you try changing the last draw() in my example to a show(), the new line will not be added.
On 05/30/2011 11:42 PM, Eric O LEBIGOT (EOL) wrote: