def update(data):
    mat.set_data(data)
return mat

def data_gen():
    while True:
        yield generate_data()
fig, ax = plt.subplots()
mat = ax.matshow(generate_data())
plt.colorbar(mat)
ani = animation.FuncAnimation(fig, update, data_gen, interval=500,
    save_count=50)
plt.show()
Animate quadratic grid changes (matshow)