| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import matplotlib.animation as animation | |
| data_path = 'dam_data.npy' | |
| data = np.load(data_path) | |
| sample_data = data[-1] | |
| fig, ax = plt.subplots() | |
| vmin = np.min(sample_data) | |
| vmax = np.max(sample_data) | |
| cax = ax.imshow(sample_data[0], cmap='viridis', animated=True, vmin=vmin, vmax=vmax) | |
| fig.colorbar(cax, ax=ax) | |
| def update(frame): | |
| cax.set_array(sample_data[frame]) | |
| ax.set_title(f'Time Step: {frame}') | |
| return cax, | |
| ani = animation.FuncAnimation(fig, update, frames=sample_data.shape[0], blit=True) | |
| ani.save('dam.gif', writer='pillow', fps=50) | |
| plt.close() |