Note
Go to the end to download the full example code.
Saving an animation¶
run this example as a notebook — or grab the .ipynb (also linked at the bottom of the page)
To save an animation, simply add the save_path kwarg and specify the path where you want to save the movie, including the extension. NOTE: saving to .mp4 (or .mov/.avi) uses matplotlib’s ffmpeg writer, so ffmpeg must be installed and on your PATH for those formats; .gif and animated .png exports are written with Pillow and need no external tools.
/home/docs/checkouts/readthedocs.org/user_builds/hypertools/checkouts/latest/hypertools/plot/backend.py:1353: UserWarning: Failed to switch to any interactive backend (TkAgg, QtAgg, Qt5Agg, Qt4Agg, GTK4Agg, GTK3Agg, WXAgg). Falling back to 'Agg'.
warnings.warn(BACKEND_WARNING)
# sphinx_gallery_thumbnail_path = '_static/thumbnails/sphx_glr_save_movie_thumb.gif'
# Code source: Andrew Heusser
# License: MIT
import hypertools as hyp
import numpy as np
data = hyp.load('weights', align='hyper')
# average the 36 subjects into two equal groups of 18
group1 = np.mean(data[:18], 0)
group2 = np.mean(data[18:], 0)
import os, tempfile
save_path = os.path.join(tempfile.mkdtemp(), 'animation.mp4')
fig, ani = hyp.plot([group1, group2], animate=True, save_path=save_path)
Total running time of the script: (0 minutes 40.339 seconds)