movie-2.py 655 B

123456789101112131415161718192021222324252627282930
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from matplotlib.animation import FuncAnimation
  4. def f(x, m, s):
  5. return (1.0/(np.sqrt(2*np.pi)*s))*np.exp(-0.5*((x-m)/s)**2)
  6. m = 0; s_start = 2; s_stop = 0.2
  7. s_values = np.linspace(s_start,s_stop,30)
  8. x = np.linspace(-3*s_start,3*s_start, 1000)
  9. max_f = f(m,m,s_stop)
  10. plt.axis([x[0],x[-1],0,max_f])
  11. plt.xlabel('x')
  12. plt.ylabel('y')
  13. y = f(x,m,s_start)
  14. lines = plt.plot(x,y) #initial plot to create the lines object
  15. def next_frame(s):
  16. y = f(x, m, s)
  17. lines[0].set_ydata(y)
  18. return lines
  19. ani = FuncAnimation(plt.gcf(), next_frame, frames=s_values, interval=100)
  20. ani.save('movie.mp4',fps=20)
  21. plt.show()