Claim 1: no precomputed array
Claim 2: no set_ydata
I have read answer from Dynamically updating plot in matplotlib and How to update a plot in matplotlib? and their scenarios are different.
Case 0, you are iteratively solving large linear algebra problem, how can you monitor convergence of the solution at real time -- so you can stop the calculation once the solution shows signs of explosion and save waiting time?
Case 1, you have a two dimensional array and you are changing value at random (i, j), you can think of this as ising model or percolation model or whatever model you are familar with. How to show the evolution of the array?
Case 2, you have a triangular mesh and you are doing depth-first search of the nodes and you want to mark the path, or you are doing something simpler: tracing the mesh boundaries using half-edge data structure. A visualization at real time is of massive help for checking correctness of the algorithm implementation.
Enough background, the 0th one can be solved by the set_ydata method if your number of iterations is not large (or you don't care about memory), but case 1 and 2? I have no hint. Currently my 'solution' is to save hundreds of figures on disk. I've tried to just plot one figure and update it, but matplotlib seems prefer waiting for everything is done and plot everything at once. Can anybody tell me how to dynamically update a figure? Thank you very much!
Test code is below (currently it only plots once in the end):
from numpy import *
import matplotlib.pyplot as plt
from time import sleep
M = zeros((5,5))
fig = plt.figure(1)
for n in range(10):
i = random.randint(5)
j = random.randint(5)
print 'open site at ', i, j
M[i, j] = 1
plt.imshow(M, 'gray', interpolation = 'nearest')
plt.plot(j, i, 'ro') # also mark open site (I have reason to do this)
fig.canvas.draw()
sleep(0.3)
plt.show()