I have a NxN grid with some values, which change every time step. I have found a way to plot a single grid configuration of this with matshow
function, but I don't know how do I update the status with every time step. Here is a simple example:
from pylab import *
from matplotlib import pyplot
a = arange(25)
a = a.reshape(5,5)
b = 10*rand(5,5)
matshow(a-b, cmap = cm.jet)
colorbar()
show()
This code produces the following picture:
Now imagine that the next time step some values change, so should this picture. This is the logic I had in mind:
from pylab import *
from matplotlib import pyplot
a = arange(25)
a = a.reshape(5,5)
time=10
for t in range(time):
b = 10*rand(5,5)
print b
matshow(a-b, cmap=cm.jet)
colorbar()
show()
This produces 10 pictures. I'd like to animate this instead producing individual pictures, and for example I'd like to choose a time step between changes (that is, frame rate).
Also, I'm open to suggestions for a different functions, if matshow
is not the way to go, but please keep it simple, I'm relatively inexperienced.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…