Advertisement
furas

Python - FuncAnimation - SO

Nov 22nd, 2016
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import matplotlib.animation as animation
  3. import random
  4.  
  5. def animate(frameno):
  6.     x = random.randint(-200, 200)
  7.     n = [x, -x]
  8.    
  9.     for rect, h in zip(rects, n):
  10.         rect.set_height(h)
  11.        
  12.     return rects
  13.  
  14. # --- init ---
  15.  
  16. fig, ax = plt.subplots()
  17. rects = plt.bar([0,1], [0,0], width=1)
  18. plt.ylim([-200, 200])
  19.  
  20. ani = animation.FuncAnimation(fig, animate, blit=True,
  21.                               interval=100, frames=100, repeat=False)
  22. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement