Opened 4 years ago

Closed 3 years ago

#22777 closed defect (fixed)

Animate in Jupyter notebook

Reported by: mforets Owned by:
Priority: blocker Milestone: sage-8.0
Component: notebook Keywords: animate jupyter plot
Cc: kcrisman Merged in:
Authors: Jeroen Demeyer, Volker Braun Reviewers: Marcelo Forets
Report Upstream: N/A Work issues:
Branch: cbf2b37 (Commits) Commit: cbf2b378b41dac16f82914fa02bbd9dae3b68d83
Dependencies: Stopgaps:

Description (last modified by jdemeyer)

The animate command allows to animate a list of frames by creating a sage.plot.animate.Animation object.

In a Jupyter notebook environment, the code below returns Animation with 20 frames, while it should have a similar behaviour as with the sage notebook (displaying a gif).

f(x) = 5*x - x^2/8 + x^3/1200
df(x) = diff(f(x),x)
max = 100
p = plot(f(x),x,0,max)
lblp = text("$y = " + latex(f(x)) + "$",[40,100],fontsize=14)
lbldp = text("$y' = " + latex(df(x)) + "$",[40,80],fontsize=14,rgbcolor='#006000')
ga = []
for argx in srange(0,max,5):
    dp = plot(f(argx) + (df(argx)*(x-argx)),x,0,max,color="#006000")
    xp = point((argx,f(argx)),rgbcolor='#800000')    

Reported in Animation doesn't work by cybervigilante.

Probably intersecting #16573, #16650 and #17783.

Change History (12)

comment:1 Changed 4 years ago by mforets

  • Description modified (diff)

comment:2 Changed 3 years ago by jdemeyer

  • Authors set to Jeroen Demeyer

comment:3 Changed 3 years ago by jdemeyer

  • Component changed from graphics to notebook
  • Priority changed from major to critical

comment:4 Changed 3 years ago by jdemeyer

  • Description modified (diff)

comment:5 Changed 3 years ago by vbraun

Last time I checked jupyter didn't support gif (hence no animated gif either).

comment:6 Changed 3 years ago by kcrisman

But see also this post about mpl html5 animations. Various other workarounds of varying quality are out there ... and there is even a request.

Last edited 3 years ago by kcrisman (previous) (diff)

comment:7 Changed 3 years ago by vbraun

  • Branch set to u/vbraun/animate_in_jupyter_notebook

comment:8 Changed 3 years ago by vbraun

  • Commit set to cbf2b378b41dac16f82914fa02bbd9dae3b68d83

The patch adds GIF support to the jupyter notebook.

Actual html5 video would be better, but also requires some encoder like ffmpeg. Whereas I think we can generate animated gif without external dependencies.

Of course you don't have to call animate(...).show(), the displayhook already renders the animation if it can. Really its our fault for having that confusingly-named show() method.

New commits:

cbf2b37Add GIF support to the Jupyter notebook display backend

comment:9 Changed 3 years ago by vbraun

  • Authors changed from Jeroen Demeyer to Jeroen Demeyer, Volker Braun
  • Status changed from new to needs_review

comment:10 Changed 3 years ago by vbraun

  • Priority changed from critical to blocker

comment:11 Changed 3 years ago by mforets

  • Reviewers set to Marcelo Forets
  • Status changed from needs_review to positive_review

looks good to me.

PS: in my (Mac osx) machine, animate produces ugly yellowish axes, see screenshot and gif. but i think this has nothing to do with the jupyter notebook itself..

comment:12 Changed 3 years ago by vbraun

  • Branch changed from u/vbraun/animate_in_jupyter_notebook to cbf2b378b41dac16f82914fa02bbd9dae3b68d83
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.