Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Animation freezes in Jupyter notebook #18580

Copy link
Copy link
Closed
@johnomotani

Description

@johnomotani
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.