Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import matplotlib.animation as animation
  4.  
  5. i = 1
  6. w = 1
  7.  
  8. N = 200
  9. alpha = 0.1
  10.  
  11. xx = []
  12. yy = []
  13. steps = 30
  14. for step in range(steps):
  15. anoms = np.random.binomial(N, alpha)
  16. x = np.random.uniform(i, i+w, size=(N-anoms,2))
  17. y = np.random.uniform(4, 5, size=(anoms,2))
  18. if step < 10:
  19. i += 0.5
  20. w += 0.5
  21. else:
  22. i -= 0.25
  23. w -= 0.25
  24. xx.append(x)
  25. yy.append(y)
  26.  
  27. x_lower, x_higher = 0, 15
  28. y_lower, y_higher = 0, 15
  29.  
  30. fig, ax = plt.subplots(figsize=(8,8))
  31.  
  32. ax = plt.axis([x_lower, x_higher, y_lower, y_higher])
  33.  
  34. anomalies, = plt.plot([0], [np.sin(0)], 'r.')
  35. typicals, = plt.plot([0], [np.sin(0)], 'b.')
  36.  
  37.  
  38. def animate(i):
  39. anomalies.set_data(yy[i][:,0], yy[i][:,1])
  40. typicals.set_data(xx[i][:,0], xx[i][:,1])
  41. return anomalies,
  42.  
  43. # create animation using the animate() function
  44. myAnimation = animation.FuncAnimation(fig, animate, frames=range(steps), interval=10, blit=True, repeat=True)
  45.  
  46. plt.show()
  47.  
  48. # Set up formatting for the movie files
  49. Writer = animation.writers['ffmpeg']
  50. writer = Writer(fps=5, metadata=dict(artist='Me'), bitrate=1800)
  51. myAnimation.save('im.mp4', writer=writer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement