Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 95dc08f

Browse files
committed
Let pause always run the event loop.
The default `start_event_loop` is not as efficient as it could be for non-interactive backends (it runs a busy loop) but if you really care you should just call time.sleep in that case. Meanwhile, this avoids the need for third-party interactive backends to register themselves into rcsetup.interactive_bk in order to be correctly pause()able.
1 parent 8aafcbf commit 95dc08f

1 file changed

Lines changed: 16 additions & 26 deletions

File tree

lib/matplotlib/pyplot.py

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ def _backend_selection():
7575
loop, and if not switches to a compatible one.
7676
"""
7777
backend = rcParams['backend']
78-
if not rcParams['backend_fallback'] or \
79-
backend not in _interactive_bk:
78+
if not rcParams['backend_fallback'] or backend not in _interactive_bk:
8079
return
8180
is_agg_backend = rcParams['backend'].endswith('Agg')
8281
if 'wx' in sys.modules and not backend in ('WX', 'WXAgg'):
@@ -275,33 +274,24 @@ def pause(interval):
275274
"""
276275
Pause for *interval* seconds.
277276
278-
If there is an active figure it will be updated and displayed,
279-
and the GUI event loop will run during the pause.
277+
If there is an active figure, it will be updated and displayed before the
278+
pause, and the GUI event loop (if any) will run during the pause.
280279
281-
If there is no active figure, or if a non-interactive backend
282-
is in use, this executes time.sleep(interval).
283-
284-
This can be used for crude animation. For more complex
285-
animation, see :mod:`matplotlib.animation`.
286-
287-
This function is experimental; its behavior may be changed
288-
or extended in a future release.
280+
This can be used for crude animation. For more complex animation, see
281+
:mod:`matplotlib.animation`.
289282
283+
This function is experimental; its behavior may be changed or extended in a
284+
future release.
290285
"""
291-
backend = rcParams['backend']
292-
if backend in _interactive_bk:
293-
figManager = _pylab_helpers.Gcf.get_active()
294-
if figManager is not None:
295-
canvas = figManager.canvas
296-
if canvas.figure.stale:
297-
canvas.draw_idle()
298-
show(block=False)
299-
canvas.start_event_loop(interval)
300-
return
301-
302-
# No on-screen figure is active, so sleep() is all we need.
303-
import time
304-
time.sleep(interval)
286+
manager = _pylab_helpers.Gcf.get_active()
287+
if manager is not None:
288+
canvas = manager.canvas
289+
if canvas.figure.stale:
290+
canvas.draw_idle()
291+
show(block=False)
292+
canvas.start_event_loop(interval)
293+
else:
294+
time.sleep(interval)
305295

306296

307297
@docstring.copy_dedent(matplotlib.rc)

0 commit comments

Comments
 (0)