Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. import numpy as np
  2. from matplotlib import pyplot as plt
  3. from matplotlib.animation import FuncAnimation
  4. plt.style.use('seaborn-pastel')
  5.  
  6.  
  7. fig = plt.figure()
  8. ax = plt.axes(xlim=(0, 4), ylim=(-2, 2))
  9. line, = ax.plot([], [], lw=3)
  10.  
  11. def init():
  12. line.set_data([], [])
  13. return line,
  14. def animate(i):
  15. x = np.linspace(0, 4, 1000)
  16. y = np.sin(2 * np.pi * (x - 0.01 * i))
  17. line.set_data(x, y)
  18. return line,
  19.  
  20. anim = FuncAnimation(fig, animate, init_func=init,
  21. frames=200, interval=20, blit=True)
  22.  
  23.  
  24. anim.save('sine_wave.gif', writer='imagemagick')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement