Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yt-project
GitHub Repository: yt-project/yt
Path: blob/main/doc/source/cookbook/matplotlib-animation.py
928 views
1
from matplotlib import rc_context
2
from matplotlib.animation import FuncAnimation
3
4
import yt
5
6
ts = yt.load("GasSloshingLowRes/sloshing_low_res_hdf5_plt_cnt_*")
7
8
plot = yt.SlicePlot(ts[0], "z", ("gas", "density"))
9
plot.set_zlim(("gas", "density"), 8e-29, 3e-26)
10
11
fig = plot.plots["gas", "density"].figure
12
13
14
# animate must accept an integer frame number. We use the frame number
15
# to identify which dataset in the time series we want to load
16
def animate(i):
17
ds = ts[i]
18
plot._switch_ds(ds)
19
20
21
animation = FuncAnimation(fig, animate, frames=len(ts))
22
23
# Override matplotlib's defaults to get a nicer looking font
24
with rc_context({"mathtext.fontset": "stix"}):
25
animation.save("animation.mp4")
26
27