Advertisement
ganryu

Untitled

Feb 7th, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.67 KB | None | 0 0
  1. """
  2. Matplotlib Animation Example
  3.  
  4. author: Jake Vanderplas
  5. email: vanderplas@astro.washington.edu
  6. website: http://jakevdp.github.com
  7. license: BSD
  8. Please feel free to use and modify this, but keep the above information. Thanks!
  9. """
  10.  
  11. import numpy as np
  12. from matplotlib import pyplot as plt
  13. from matplotlib import animation
  14.  
  15. # First set up the figure, the axis, and the plot element we want to animate
  16. fig = plt.figure()
  17. ax = plt.axes(xlim=(-2, 2), ylim=(-2, 2))
  18. line, = ax.plot([], [], lw=2)
  19.  
  20. def trayectoria(fase, amplitud, v_angular, t):
  21.     return amplitud * np.sin ((v_angular * t)+ fase)
  22.  
  23. xdata = []
  24. ydata = []
  25.  
  26. # initialization function: plot the background of each frame
  27. def init():
  28.     line.set_data([], [])
  29.     return line,
  30.  
  31. # animation function.  This is called sequentially
  32. def animate(t):
  33.     A = 3
  34.     B = 5
  35.     t_scaled = -np.pi + (t * (np.pi * 2)) / 1000
  36.     delta = np.pi / 2
  37.     x = np.sin(A * t_scaled + delta)
  38.     y = np.sin(B * t_scaled)
  39.     xdata.append(x)
  40.     ydata.append(y)
  41.  
  42.     line.set_data(xdata, ydata)
  43.     return line,
  44.  
  45. # call the animator.  blit=True means only re-draw the parts that have changed.
  46. anim = animation.FuncAnimation(fig, animate, init_func=init,
  47.                                frames=1000, interval=1, blit=True)
  48.  
  49. # save the animation as an mp4.  This requires ffmpeg or mencoder to be
  50. # installed.  The extra_args ensure that the x264 codec is used, so that
  51. # the video can be embedded in html5.  You may need to adjust this for
  52. # your system: for more information, see
  53. # http://matplotlib.sourceforge.net/api/animation_api.html
  54. anim.save('basic_animation.mp4', fps=30, extra_args=['-vcodec', 'libx264'])
  55.  
  56. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement