From: Eric Firing <efiring@...229...>
Subject: Re: [matplotlib-devel] repeated calls to show() are now OK?
To: "Michiel de Hoon" <mjldehoon@...42...>
Cc: "John Hunter" <jdh2358@...149...>, "matplotlib development list" <email@example.com>
Date: Saturday, June 12, 2010, 11:32 PM
On 06/12/2010 05:37 AM, Michiel de > Hoon wrote:
> --- On Sat, 6/12/10, Eric Firing<efiring@...229...> > wrote:
>>> With TkAgg on Mac OS X, the first call to
>>> blocks, and returns when all figures are
closed by the user.
>>> However, subsequent calls to show() return
>> This is anomalous, then; on linux, no call to show
>> with tkagg.
>> Puzzling difference.
> If I remove the _needmain stuff in the show() function
in the TkAgg backend, then each call to show() blocks on Mac
OS X with the TkAgg backend, which (in my understanding) is
the desired behavior. I don't know the purpose of _needmain
in the show() function, other than to disallow multiple
calls to show().
I committed a change to backend_tkagg that leaves the show
functionality exactly as it is at present, but that
facilitates testing of a simpler version that I think is
more consistent with the other backends and with what we
want. (I have appended the whole function to this
message--see below for additional explanation.)
I have also done some more exploration and testing, and
here are my tentative conclusions:
1) We should aim for a show() that blocks until all windows
are closed, on all backends, and in all environments.
I think this is clearly something that many users would
like; it has reasonable use cases; and it is simple,
consistent, and easy to explain.
2) The big problem is the "in all environments" part of
that statement. We probably can't achieve the goal,
but I suspect that over the long term we can approach it,
and the result will be "good enough".
3) As a step in that direction, I would like to see enough
testing of Tk with show(block=True) so that, if it works, we
can transition towards that behavior as the default,
deprecate the old behavior, and eventually eliminate
it. Presently, TkAgg is most anomalous among the major
4) Leaving the documentation (all in the FAQ) with its
caution against anything but a single show() at the end of a
script is fine for 1.0; supporting multiple calls to a
blocking show under mildly restrictive conditions is a
reasonable goal for a subsequent release.
Show all figures.
Temporary, experimental kwarg \*block\*
defaults to False to
provide the behavior present throughout mpl
history to date:
interactive mode is forced on, and show does
Set \*block\* to True to test the proposed new
consistent with other backends, in which show
does not affect
interactive mode, and always blocks until all
figures are closed.
In addition, the rcParam['tk.pythoninspect']
Use this kwarg only for testing; other
backends do not accept
a kwarg to show, and might never do so.
for manager in Gcf.get_all_fig_managers():
# proposed new behavior; seems
to make this backend consistent
# with others, with no
drawbacks identified yet.
# long-time behavior:
non-blocking, forces interactive mode
os.environ['PYTHONINSPECT'] = '1'
show._needmain = True # This can go away
if we eliminate block=False option.