2012-01-22 7 views
4

다음 코드프로그램 실행 중에 Matplotlib 플롯을 업데이트하는 방법은 무엇입니까?

plt.figure(1) 
plt.subplot(211) 
plt.axis([0,100, 95, 4000]) 
plt.plot(array1,array2,'r') 
plt.ylabel("label") 
plt.xlabel("label") 
plt.subplot(212) 
plt.specgram(array3) 
plt.show() 

두 좋은 다이어그램을 생성합니다. 그러나 창을 닫지 않고도 콘텐츠를 어떻게 업데이트합니까?

하나의 스레드에서 창을 만들어야하고 변수가 주 코드에서 업데이트되는 동안 변수를 사용하여 창이 업데이트되고 있습니다.

어떻게 할 수 있습니까?

답변

6

몇 가지 옵션이 있습니다. 하나는 mpl examples을 사용하는 훌륭한 예입니다. 둘째 루프가 자기 자신을 쓰고 있으므로 무엇이 진행되고 있는지 이해할 수 있습니다. 다음은 pylab.draw() 함수 대신 쇼(), 그것은 공상하지 사용하여 간단한 예이지만, 당신이 기본적인 물건을 이해할 수 :

import pylab 
import time 

pylab.ion() # animation on 

# Note the comma after line. This is placed here because 
# plot returns a list of lines that are drawn. 
line, = pylab.plot(0,1,'ro',markersize=6) 
pylab.axis([0,1,0,1]) 

line.set_xdata([1,2,3]) # update the data 
line.set_ydata([1,2,3]) 
pylab.draw() # draw the points again 
time.sleep(6) 

line1, = pylab.plot([4],[5],'g*',markersize=8) 
pylab.draw() 

for i in range(10): 
    line.set_xdata([1,2,3]) # update the data 
    line.set_ydata([1,2,3]) 
    pylab.draw() # draw the points again 
    time.sleep(1) 

print "done up there" 
line2, = pylab.plot(3,2,'b^',markersize=6)  
pylab.draw() 

time.sleep(20) 

도움이 되었기를 바랍니다.

관련 문제