Animate a list of 2d arrays

Viewed 80

I have a list of 2 dimensional NxN numpy arrays each with non-negative integer entries.

I want to create an animation which goes through each array and plots the associated array as a surface where each integer entry in the array represents a z value for its (x,y) position.

I was able to plot a single array as shown below. I know we can use the animation function but after several attempts I have failed and need some help.

Thank you.

I was able to plot a single array as shown below. I know we can use the animation function but after several attempts I have failed and need some help.

``# Creating live animation of avalancheimport matplotlib.pyplot as pltfrom mpl_toolkits.mplot3d import Axes3Dfrom matplotlib import animation

nx, ny = N, Nx = range(nx)y = range(ny)

data = grid

"Create figure and add axis"fig = plt.figure()ax = fig.add_subplot(111, projection='3d')

"Adjusting z axis scale"scale_x = 1scale_y = 1scale_z = 1/Nax.get_proj = lambda: np.dot(Axes3D.get_proj(ax), np.diag([scale_x, scale_y, scale_z, 1]))

"Creating mesh grid and plotting"X, Y = np.meshgrid(x, y)ax.plot_surface(X.T, Y.T, data)plt.show()`
0 Answers
Related