Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. from matplotlib import animation, rc
  5. from IPython.display import HTML
  6. from random import randint
  7.  
  8. last_number = 1
  9. range_low = 1
  10. range_high = 100
  11.  
  12. dim = range_high - range_low + 1
  13.  
  14. numbers = np.arange(range_low, range_high + 1, dtype=int)
  15. numbers_map = np.zeros((dim, dim), dtype=int)
  16.  
  17. fig = plt.figure()
  18. im = plt.imshow(numbers_map)
  19.  
  20. def init():
  21.   im.set_data(np.zeros((dim, dim)))
  22.   return im
  23.  
  24. def number_generator():
  25.   while True:
  26.     yield randint(range_low, range_high)
  27.    
  28. def animate(number):
  29.   numbers_map[last_number - range_low, number - range_low] += 1
  30.   im.set_data(numbers_map)
  31.   return im
  32.  
  33. anim = animation.FuncAnimation(fig, animate, init_func=init, frames=number_generator, interval=100,
  34.                                blit=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement