import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
def update_grid(data):
global grid
x = np.random.randint(N)
y = np.random.randint(N)
grid[x, y] += 1
#new_grid = grid.copy()
counter = 0
while np.max(grid) >=4:
x, y = np.where(grid >= 4)
grid[x,y] = 0
grid[x%N, (y-1)%N] += 1
grid[x%N,(y+1)%N] += 1
grid[(x-1)%N,y%N] += 1
grid[(x+1)%N,y%N] += 1
#At the border
counter +=1
mat.set_data(grid)
print(grid)
return [mat]
N = 10
grid = np.zeros((N, N))
fig, ax = plt.subplots()
mat = ax.matshow(grid)
ani = animation.FuncAnimation(fig, update_grid, interval = 1 ,save_count = 50,blit=True)
plt.show()
I am not sure as to why the plot is not updating at every interval and it keeps on giving me a blank.