2014-06-23 1 views
1

Mac OS 및 ipython 노트북 2.0에서 (실행시) unlike this answer에 애니메이션을 적용하려고합니다. 축이 업데이트되지 않습니다Mac OS 용 ipython 2의 플롯 애니메이션

거의 ( clear_output에 의해 수정 된 이전 문제를) 깜박하지 않고 print대로 작동 작동하는 것 같다
%pylab inline 
import time, sys 
import numpy as np 
import matplotlib.pyplot as plt 
from IPython.display import clear_output 
f, ax = plt.subplots() 

x = np.linspace(0,6,200) 

for i in range(10): 
    y = i/10*np.sin(x) 
    print i 
    ax.plot(x,y) 
    time.sleep(0.1) 
    clear_output(True) 
    display(f) 
    ax.cla() # turn this off if you'd like to "build up" plots 
plt.close() 

:하지만, 나는 다음과 같은 코드가 있습니다.

답변

1

여기에서 문제는 i은 정수이므로 y = i/10*np.sin(x) 줄은 항상 0을 반환하는 정수 나누기를 수행합니다. 애니메이션 처리 중입니다! 그러나 결과는 당신이 그렇게하면, 당신이 아주 좋은 방법으로 애니메이션을하지 않는 것을 알 수 있습니다

y = float(i)/10*np.sin(x) 

0으로 변경이 라인에서 평면 라인은 항상있다. 더 잘 보이게하기 위해 Matplotlib가 자동으로 수행하는 대신 y 축 한계를 명시 적으로 설정할 수 있습니다. 루프 내부에 줄을 추가하십시오.

ax.set_ylim(-1, 1) 

마지막 코드는 잘 생생합니다.

%pylab inline 
import time, sys 
import numpy as np 
import matplotlib.pyplot as plt 
from IPython.display import clear_output 
f, ax = plt.subplots() 

x = np.linspace(0,6,200) 

for i in range(10): 
    y = float(i)/10*np.sin(x) 
    print i 
    ax.set_ylim(-1, 1) 
    ax.plot(x,y) 
    time.sleep(0.1) 
    clear_output(True) 
    display(f) 
    ax.cla() # turn this off if you'd like to "build up" plots 
plt.close()