I have a python code in which I calculate a quantity for a large number of values of a parameter and then plot the quantity as a function of a parameter. Here is an example
JavaScript
x
7
1
t = np.linspace(1,100,10000)
2
q = np.zeros(10000)
3
for i in np.arange(10000)
4
q[i] = func(t[i])
5
plt.plot(t,q)
6
plt.show()
7
However I want that the plot to get dynamically updated such that every time a new element of the q
array is calculated it is added to the plot. How can I do that?
Advertisement
Answer
JavaScript
1
17
17
1
from pylab import *
2
3
import time
4
5
ion()
6
7
tstart = time.time() # for profiling
8
x = arange(0,2*pi,0.01) # x-array
9
line, = plot(x,sin(x))
10
11
for i in arange(1,200):
12
line.set_ydata(sin(x+i/10.0)) # update the data
13
draw() # redraw the canvas
14
15
16
print 'FPS:' , 200/(time.time()-tstart)
17
ripped from the post i put in the comments …