hvplot icon indicating copy to clipboard operation
hvplot copied to clipboard

Support for saving animations in mp4 format

Open tomchor opened this issue 4 years ago • 3 comments

Problem: I frequently have to create animations from my xarray datasets. Currently the only way I can do that easily (i.e. without manually saving each frame as a separate png figure and then sticking them together with ffmpeg) is by using matplotlib. However, matplottlib is notoriously slow and that can be pretty frustrating. Sometimes I have to wait a full hour for all my frames to save!

I love the simplicity of hvplot! And, given that hvplot has the flexibility to use faster backends, it would be awesome if I could something like

anim = da.hvplot(groupy="time", **kwargs)
hvplot.save(anim, "anim.mp4")

However, doing this fails. The closest alternative possible seems to me to be hvplot.save(anim, "anim.gif"), but inexplicably the output is still an html file. (I also haven't been able to make the fmt=png alternative work with me, so I'm not sure what that produces.)

Is there any chance this feature can be added to hvplot?

In the mean time, is there anything I can do with hvplot to plot animations (relatively) fast and simple?

Thanks!

tomchor avatar Feb 03 '21 19:02 tomchor

This would indeed be great. HoloViews does have support for rendering to mp4 but only using the matplotlib backend, which isn't supported for hvPlot - yet anyway. That said you will probably not see the performance gains you want with the Bokeh backend since while rendering is fast exporting the frames is still relatively slow. Nonetheless it's a nice feature request.

The closest alternative possible seems to me to be hvplot.save(anim, "anim.gif"),

So this is definitely a bug since this should be supported. Could you try using dynamic=False in the hvplot call?

philippjfr avatar Feb 04 '21 10:02 philippjfr

Using dynamic=False does work for fmt="gif", so thanks for the tip on that one. That's not a very good choice for me though because you can't control the frame rate. (At least I couldn't find a way.)

@philippjfr So, do you have any suggested workaround for my case? Or is using gif my best option here?

tomchor avatar Feb 04 '21 14:02 tomchor

  • [ ] Now that hvPlot supports Matplotlib it may be nice to document how to create animations.

maximlt avatar Oct 18 '22 23:10 maximlt