Skip to content

Commit

Permalink
Make the update function going to animate_polygon_list from animate_p…
Browse files Browse the repository at this point in the history
…olygon fully encapsulated, use the t dimension to set the number of frames.
  • Loading branch information
mrhardman committed Feb 14, 2025
1 parent bc4d9eb commit 108989e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
13 changes: 6 additions & 7 deletions xbout/boutdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,7 @@ def is_list(variable):

if ndims == 3:
if this_poloidal_plot:
polys, da, update_func = animate_polygon(
update_func = animate_polygon(
data,
ax=ax,
cax=cax,
Expand All @@ -1552,7 +1552,7 @@ def is_list(variable):
animate=False,
**this_kwargs,
)
animate_data.append([polys,da,update_func])
animate_data.append(update_func)
else:
raise ValueError(
"Unsupported option "
Expand All @@ -1572,15 +1572,14 @@ def is_list(variable):
ax.set_title(this_title)

def update(frame):
for list in animate_data:
(polys, da, update_func) = list
for update_func in animate_data:
# call update function for each axes
update_func(frame,polys,da)
update_func(frame)

# make the animation for all the subplots simultaneously
# use the last data array da to choose the number of frames
# use time data array "t" to choose the number of frames
# assumes time dimension same length for all variables
anim = FuncAnimation(fig=fig, func=update, frames=np.shape(da.data)[0], interval=30)
anim = FuncAnimation(fig=fig, func=update, frames=self.data["t"].data.size, interval=30)
if tight_layout:
if subplots_adjust is not None:
warnings.warn(
Expand Down
7 changes: 2 additions & 5 deletions xbout/plotting/animate.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,9 +868,6 @@ def update(frame):
ani = matplotlib.animation.FuncAnimation(fig=fig, func=update, frames=np.shape(da.data)[0], interval=30)
return ani
else:
# return function and data for making the animation
def update_out(frame,polys,da):
colors = da.data[frame,:,:].flatten()
polys.set_array(colors)
return polys, da, update_out
# return function for making the animation
return update

0 comments on commit 108989e

Please sign in to comment.