In [1]:
import numpy as np
import matplotlib.pyplot as plt
import random as rd
from matplotlib import animation, rc
from IPython.display import HTML


# First set up the figure, the axis, and the plot element we want to animate
fig,ax =plt.subplots()

N=3
M=np.zeros([N,N],int)
line=ax.imshow(M,vmin=0,vmax=10,alpha=1,interpolation="none")

# initialization function: plot the background of each frame


# animation function. This is called sequentially
def animate(i):
    M[rd.randint(0,N-1),rd.randint(0,N-1)]+=1
    line.set_data(M)
    return(line,)

anim = animation.FuncAnimation(fig, animate,frames=100, interval=20, blit=True)
HTML(anim.to_html5_video())
Out[1]:
In [ ]: