我复制了pyplot.pause()
这里的代码:
def pause(interval):
"""
Pause for *interval* seconds.
If there is an active figure it will be updated and displayed,
and the GUI event loop will run during the pause.
If there is no active figure, or if a non-interactive backend
is in use, this executes time.sleep(interval).
This can be used for crude animation. For more complex
animation, see :mod:`matplotlib.animation`.
This function is experimental; its behavior may be changed
or extended in a future release.
"""
backend = rcParams['backend']
if backend in _interactive_bk:
figManager = _pylab_helpers.Gcf.get_active()
if figManager is not None:
canvas = figManager.canvas
canvas.draw()
show(block=False)
canvas.start_event_loop(interval)
return
# No on-screen figure is active, so sleep() is all we need.
import time
time.sleep(interval)
如您所见,它调用start_event_loopinterval
,它会在几秒钟内启动一个单独的粗略事件循环。如果interval
== 0 似乎是后端依赖会发生什么。例如,对于 WX 后端,值为 0 意味着这个循环是阻塞的并且永远不会结束(我必须查看这里的代码,它没有出现在文档中。参见第 773 行)。
简而言之,0是一个特例。你不能把它设置成一个小值,例如0.1秒吗?
上面的pause
文档字符串说它只能用于粗略的动画,如果你想要更复杂的东西,你可能不得不求助于动画模块。