Path: blob/main/doc/source/cookbook/matplotlib-animation.py
928 views
from matplotlib import rc_context1from matplotlib.animation import FuncAnimation23import yt45ts = yt.load("GasSloshingLowRes/sloshing_low_res_hdf5_plt_cnt_*")67plot = yt.SlicePlot(ts[0], "z", ("gas", "density"))8plot.set_zlim(("gas", "density"), 8e-29, 3e-26)910fig = plot.plots["gas", "density"].figure111213# animate must accept an integer frame number. We use the frame number14# to identify which dataset in the time series we want to load15def animate(i):16ds = ts[i]17plot._switch_ds(ds)181920animation = FuncAnimation(fig, animate, frames=len(ts))2122# Override matplotlib's defaults to get a nicer looking font23with rc_context({"mathtext.fontset": "stix"}):24animation.save("animation.mp4")252627