Closed
Description
Bug report
Bug summary
A FuncAnimation
in a Jupyter notebook runs through once but freezes when it should repeat.
Code for reproduction
%matplotlib notebook
import matplotlib as mpl
from matplotlib import pyplot as plt
import numpy as np
fig = plt.figure()
nt = 25
t = np.linspace(0,1,nt)
f = np.sin(2.*np.pi*t)
ax = plt.axes(xlim=[0,1],ylim=[-1,1])
line = ax.plot(t[:1], f[:1])[0]
def update_func(i):
line.set_xdata(t[:i])
line.set_ydata(f[:i])
anim = mpl.animation.FuncAnimation(fig, update_func, nt, repeat=True)
Passing repeat_delay=1
to FuncAnimation
on the last line prevents the error. It looks like having repeat_delay=0
sets TimerTornado.interval
to 0
, but tornado.ioloop.PeriodicCallback
requires a positive value for interval
.
Actual outcome
This error appears in the console when the animation crashes.
ERROR:tornado.application:Exception in callback <bound method TimerBase._on_timer of <matplotlib.backends.backend_webagg_core.TimerTornado object at 0x7f8627585610>>
Traceback (most recent call last):
File ".../site-packages/tornado/ioloop.py", line 907, in _run
return self.callback()
File ".../site-packages/matplotlib/backend_bases.py", line 1194, in _on_timer
ret = func(*args, **kwargs)
File ".../site-packages/matplotlib/animation.py", line 1432, in _step
self.event_source.interval = self._repeat_delay
File ".../site-packages/matplotlib/backend_bases.py", line 1135, in interval
self._timer_set_interval()
File ".../site-packages/matplotlib/backends/backend_webagg_core.py", line 537, in _timer_set_interval
self._timer_start()
File ".../site-packages/matplotlib/backends/backend_webagg_core.py", line 518, in _timer_start
self._timer = tornado.ioloop.PeriodicCallback(
File ".../site-packages/tornado/ioloop.py", line 873, in __init__
raise ValueError("Periodic callback must have a positive callback_time")
ValueError: Periodic callback must have a positive callback_time
Expected outcome
The animation plays continuously.
Matplotlib version
- Operating system: Linux Mint 19
- Matplotlib version: 3.3.2
- Matplotlib backend (
print(matplotlib.get_backend())
): nbAgg - Python version: 3.8.5
- Jupyter version (if applicable): 6.1.4
- Other libraries:
- IPython: 7.18.1
- tornado: 6.0.4
Installed all packages from conda, using conda-forge