Guest User

Untitled

a guest
Oct 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. # This import registers the 3D projection, but is otherwise unused.
  2. from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import
  3.  
  4. import matplotlib.pyplot as plt
  5. import numpy as np
  6. from IPython.display import HTML
  7.  
  8.  
  9. def generate(X, Y, phi):
  10. R = 1 - np.sqrt(X**2 + Y**2)
  11. return np.cos(2 * np.pi * X + phi) * R
  12.  
  13. fig = plt.figure()
  14. ax = fig.add_subplot(111, projection='3d')
  15.  
  16. # Make the X, Y meshgrid.
  17. xs = np.linspace(-1, 1, 50)
  18. ys = np.linspace(-1, 1, 50)
  19. X, Y = np.meshgrid(xs, ys)
  20.  
  21. # Set the z axis limits so they aren't recalculated each frame.
  22. ax.set_zlim(-1, 1)
  23.  
  24. #animation function
  25. phi = np.linspace(0, 180. / np.pi, 100)
  26. ims = []
  27. for i in range(100):
  28. at_z = phi[i]
  29. Z = generate(X,Y,at_z)
  30. im = ax.plot_wireframe(X, Y, Z, rstride=2, cstride=2)
  31. ims.append([im])
  32.  
  33. ani = animation.ArtistAnimation(fig, ims, interval=100)
  34.  
  35. HTML(ani.to_html5_video())
Add Comment
Please, Sign In to add comment