Advertisement
furas

matplotlib - animation sinus and points

Apr 26th, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. # inne znaczniki/markery zamiast kropki
  2. # https://matplotlib.org/api/markers_api.html
  3.  
  4. import numpy as np
  5. import matplotlib.pyplot as plt
  6. import matplotlib.animation as animation
  7.  
  8. fig, ax = plt.subplots()
  9.  
  10. x = np.arange(0, 2*np.pi, 0.01)
  11.  
  12. center = len(x)//2
  13.  
  14. line, = ax.plot(x, np.sin(x), 'red')
  15. point1, = ax.plot(x[center//2], np.sin(x[center//2]), 'go')
  16. point2, = ax.plot(x[center], np.sin(x[center]), 'go')
  17. point3, = ax.plot(x[center*3//2], np.sin(x[center*3//2]), 'go')
  18.  
  19. def animate(i):
  20.     line.set_ydata(np.sin(x+i/10.0))
  21.     point1.set_ydata(np.sin(x[center//2]+i/10.0))
  22.     point2.set_ydata(np.sin(x[center]+i/10.0))
  23.     point3.set_ydata(np.sin(x[center*3//2]+i/10.0))
  24.     return line, point1, point2, point3
  25.  
  26. ani = animation.FuncAnimation(fig, animate, len(x), interval=50, blit=True)
  27. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement