2016-07-26 4 views
4

를 다시 실행하지 않고하기 matplotlib 애니메이션을 재설정 : 내가 처음부터 내 코드를 실행하면어떻게이 큰 데이터 세트의 세그먼트를 애니메이션하기 matplotlib의 FuncAnimation 기능을 사용하고 스크립트

fig = plt.figure(figsize=(15, 11.5)) 
ax = fig.add_subplot(111, aspect='equal', autoscale_on=False, 
        xlim=(x1,x2), ylim=(y1, y2)) 

data,=ax.plot([],[],'o') 

def init(): 
    data.set_data([],[]) 
    return data 


def animate(t): 
    global x_pos,y_pos 
    data.set_data(x_pos[t],y_pos[t]) 
    return data 

ani=animation.FuncAnimation(fig,animate,frames=duration,interval=20, 
          init_func=init,blit=True) 


plt.show() 

이가 잘 작동합니다. 그러나 큰 데이터 집합을로드하고 전처리하는 작업에는 몇 분이 걸리기 때문에 테스트하고 애니메이션을 적용하는 데 필요한 코드 조각 만 실행하고 싶습니다.

그러나 애니메이션을 닫고 다시 실행 해보면 빈 그림 만 남았습니다. 점이 그려지 지 않고 animate() 함수가 호출되지 않습니다 (print 문을 사용하여 테스트했습니다).

나는 음모와 그림 삭제 시도 :

plt.clf() 
fig.close() 
plt.clear(figure) 

을하고 다른 그림 번호를 시도하지만 결과는 동일합니다.

전체 스크립트를 다시 실행하지 않고 애니메이션을 다시 실행할 수 있도록 애니메이션을 지울 수 있습니까?

답변

1

이 시도 :

ani.frame_seq = ani.new_frame_seq()