Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This import registers the 3D projection, but is otherwise unused.
- from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import
- import matplotlib.pyplot as plt
- import numpy as np
- from IPython.display import HTML
- def generate(X, Y, phi):
- R = 1 - np.sqrt(X**2 + Y**2)
- return np.cos(2 * np.pi * X + phi) * R
- fig = plt.figure()
- ax = fig.add_subplot(111, projection='3d')
- # Make the X, Y meshgrid.
- xs = np.linspace(-1, 1, 50)
- ys = np.linspace(-1, 1, 50)
- X, Y = np.meshgrid(xs, ys)
- # Set the z axis limits so they aren't recalculated each frame.
- ax.set_zlim(-1, 1)
- #animation function
- phi = np.linspace(0, 180. / np.pi, 100)
- ims = []
- for i in range(100):
- at_z = phi[i]
- Z = generate(X,Y,at_z)
- im = ax.plot_wireframe(X, Y, Z, rstride=2, cstride=2)
- ims.append([im])
- ani = animation.ArtistAnimation(fig, ims, interval=100)
- HTML(ani.to_html5_video())
Add Comment
Please, Sign In to add comment