Make a simple gif movie¶
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
import sandplover as spl
def update_field(i):
im.set_data(golf['eta'][i, :, :])
golf = spl.sample_data.golf()
time_idxs = np.arange(0, golf.shape[0]-1)
cmap, norm = spl.plot.cartographic_colormap(H_SL=0.0, h=4.5, n=1.0)
fig, ax = plt.subplots()
im = ax.imshow(
golf['eta'][0, :, :],
extent=golf.extent,
cmap=cmap, norm=norm
)
Then, make the animation with matplotlib’s FuncAnimation.
import os
os.makedirs("../../../../build/plot_directive/guides/examples/plot/", exist_ok=True)
anim = animation.FuncAnimation(
fig, update_field,
frames=golf.shape[0]-1,
interval=20,
blit=False)
anim.save('../../../../build/plot_directive/guides/examples/plot/simple_movie.gif', fps=30)
plt.show()
anim = animation.FuncAnimation(
fig, update_field, frames=golf.shape[0] - 1, interval=20
)
anim.save("simple_movie.gif", fps=30)
plt.show()
And view the gif: