Advertisement
ganryu

Untitled

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