Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. """
  2. oscillating_circle.py
  3.  
  4. A simple matplotlib animation example that shows an oscillating circle.
  5.  
  6. electronut.in
  7.  
  8. """
  9. import matplotlib.pyplot as plt
  10. import matplotlib.animation as animation
  11.  
  12. import math
  13. import numpy as np
  14.  
  15. count = 0
  16. def update(frameNum, a0):
  17. global count
  18. A = math.sin(math.radians(count))
  19. x = [A*math.cos(a) for a in np.arange(0, 2*math.pi+0.1, 0.1)]
  20. y = [math.sin(a) for a in np.arange(0, 2*math.pi+0.1, 0.1)]
  21. a0.set_data(x, y)
  22. count = (count + 1) % 360
  23.  
  24. fig = plt.figure()
  25. ax = plt.axes(xlim=(-1, 1), ylim=(-1, 1))
  26. a0, = ax.plot([], [])
  27. anim = animation.FuncAnimation(fig, update,
  28. fargs=(a0,),
  29. interval=20)
  30. # show plot
  31. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement