2012-10-01 42 views
0

我有一個python代碼,我在其中計算大量參數值的數量,然後將數量作爲參數的函數繪製。這裏是不過我想,該地塊得到動態更新,使得每個計算q陣列的一個新元素時它被添加到情節的例子實時更新python中的圖形

t = np.linspace(1,100,10000) 
q = np.zeros(10000) 
for i in np.arange(10000) 
    q[i] = func(t[i]) 
plt.plot(t,q) 
plt.show() 

。我怎樣才能做到這一點?

+0

http://stackoverflow.com/questions/5179589/how-to-achieve-continuous-3d-plotting-ie-update- a-figure-using-python-and-ma –

+0

http://stackoverflow.com/questions/15930529/python-matplotlib-dynamically-update-plot-array-length-not-known-a-priori – tacaswell

回答

2
from pylab import * 

import time 

ion() 

tstart = time.time()    # for profiling 
x = arange(0,2*pi,0.01)   # x-array 
line, = plot(x,sin(x)) 

for i in arange(1,200): 
    line.set_ydata(sin(x+i/10.0)) # update the data 
    draw()       # redraw the canvas 


print 'FPS:' , 200/(time.time()-tstart) 

從我把意見後撕開......

+0

我不是真的理解如何在我的情況下實現這一點,因爲在這種情況下,它會更新'line.set_ydata'行中的完整數組,在每次更新數組的新元素時,就像我的情況一樣。 – lovespeed

+0

@SthitadhiRoy簽出[這個答案](http://stackoverflow.com/questions/15930529/python-matplotlib-dynamically-update-plot-array-length-not-known-a-priori)。它可能會幫助你。 – Schorsch