@@ -52,8 +52,14 @@ ds = sdfxr.open_mfdataset("tutorial_dataset_1d/*.sdf")
5252# Access a DataArray within the Dataset
5353da = ds["Derived_Number_Density_Electron"]
5454
55+ fig, ax = plt.subplots()
56+
5557# Create the FuncAnimation object
56- anim = da.epoch.animate()
58+ anim = da.epoch.animate(ax=ax)
59+
60+ # Matplotlib will attempt to display the first frame of the video
61+ # and since we don't want that on the documentation we close it
62+ plt.close(fig)
5763
5864# Display animation as jshtml
5965anim.show()
@@ -82,7 +88,9 @@ Plotting a 2D simulation can be done in exactly the same way.
8288``` {code-cell} ipython3
8389ds = sdfxr.open_mfdataset("tutorial_dataset_2d/*.sdf")
8490da = ds["Derived_Number_Density_Electron"]
85- anim = da.epoch.animate()
91+ fig, ax = plt.subplots()
92+ anim = da.epoch.animate(ax=ax)
93+ plt.close(fig)
8694anim.show()
8795```
8896
@@ -91,8 +99,11 @@ plot it as a <inv:#xarray.plot.line>.
9199
92100``` {code-cell} ipython3
93101da = ds["Derived_Number_Density_Electron"]
102+ fig, ax = plt.subplots()
103+
94104da_lineout = da.sel(Y_Grid_mid = 1e-6, method = "nearest")
95- anim = da_lineout.epoch.animate(title = "Y = 1e-6 [m]")
105+ anim = da_lineout.epoch.animate(ax = ax, title = "Y = 1e-6 [m]")
106+ plt.close(fig)
96107anim.show()
97108```
98109
@@ -107,8 +118,10 @@ same way a 2D simulation can be plotted along a line.
107118ds = sdfxr.open_mfdataset("tutorial_dataset_3d/*.sdf")
108119
109120da = ds["Derived_Number_Density"]
110- da_lineout = da.sel(Y_Grid_mid = 0, method="nearest")
111- anim = da_lineout.epoch.animate(title = "Y = 0 [m]", fps = 2)
121+ da_lineout = da.sel(Y_Grid_mid = 0, method = "nearest")
122+ fig, ax = plt.subplots()
123+ anim = da_lineout.epoch.animate(ax = ax, title = "Y = 0 [m]", fps = 2)
124+ plt.close(fig)
112125anim.show()
113126```
114127
@@ -118,7 +131,9 @@ the animation.
118131``` {code-cell} ipython3
119132ds = sdfxr.open_dataset("tutorial_dataset_3d/0005.sdf")
120133da = ds["Derived_Number_Density"]
121- anim = da.epoch.animate(t = "X_Grid_mid")
134+ fig, ax = plt.subplots()
135+ anim = da.epoch.animate(ax = ax, t = "X_Grid_mid")
136+ plt.close(fig)
122137anim.show()
123138```
124139
@@ -144,7 +159,9 @@ ds = xr.open_mfdataset(
144159 )
145160
146161da = ds["Derived_Number_Density_Beam_Electrons"]
147- anim = da.epoch.animate(move_window=True, fps = 5)
162+ fig, ax = plt.subplots()
163+ anim = da.epoch.animate(ax = ax, move_window = True, fps = 5)
164+ plt.close(fig)
148165anim.show()
149166```
150167
@@ -175,12 +192,15 @@ da.data = da.values * 1e-6
175192da.attrs["units"] = "cm$^{-3}$"
176193da.attrs["long_name"] = "$n_e$"
177194
195+ fig, ax = plt.subplots()
178196anim = da.epoch.animate(
197+ ax = ax,
179198 fps = 2,
180199 max_percentile = 95,
181200 title = "Target A",
182201 cmap = "plasma",
183- )
202+ )
203+ plt.close(fig)
184204anim.show()
185205```
186206
@@ -197,14 +217,16 @@ same axis.
197217``` {code-cell} ipython3
198218ds = sdfxr.open_mfdataset("tutorial_dataset_1d/*.sdf")
199219
220+ fig, ax = plt.subplots()
200221anim = ds.epoch.animate_multiple(
201222 ds["Derived_Number_Density_Electron"],
202223 ds["Derived_Number_Density_Ion"],
203- datasets_kwargs=[{"label": "Electron"}, {"label": "Ion"}],
204- ylim=(0e27,4e27),
205- ylabel="Derived Number Density [1/m$^3$]"
224+ ax = ax,
225+ datasets_kwargs = [{"label": "Electron"}, {"label": "Ion"}],
226+ ylim = (0e27,4e27),
227+ ylabel = "Derived Number Density [1/m$^3$]"
206228)
207-
229+ plt.close(fig)
208230anim.show()
209231```
210232
@@ -223,6 +245,8 @@ from matplotlib.colors import LogNorm
223245
224246ds = sdfxr.open_mfdataset("tutorial_dataset_2d/*.sdf")
225247
248+ fig, ax = plt.subplots()
249+
226250flux_magnitude = np.sqrt(
227251 ds["Derived_Poynting_Flux_x"]**2 +
228252 ds["Derived_Poynting_Flux_y"]**2 +
@@ -242,10 +266,12 @@ flux_norm = LogNorm(
242266anim = ds.epoch.animate_multiple(
243267 ds["Derived_Number_Density_Electron"],
244268 flux_masked,
245- datasets_kwargs=[
269+ ax = ax,
270+ datasets_kwargs = [
246271 {"alpha": 1.0},
247272 {"cmap": "hot", "norm": flux_norm, "alpha": 0.9},
248273 ],
249274)
275+ plt.close(fig)
250276anim.show()
251277```
0 commit comments