안녕하세요,님께 StackOverfloooow 멤버, matplotlib의 FuncAnimation 모듈을 이해하는 데 문제가 있습니다. 좀 도와 줄래? 나는 두 가지 질문이 있습니다 Python Matplotlib FuncAnimation
- 왜 모두
init
죽지 않고animate
기능 만 다시PLOT
제공 후 쉼표가 필요? - 내 코드가
time_text
을 업데이트하지 않는 이유는 무엇입니까? 모든 애니메이션 후에 t를 출력하도록하면 콘솔에 하나를 추가하지만 텍스트는 플롯에서 업데이트되지 않습니다.
.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
fig = plt.figure()
sub = fig.add_subplot(111,xlim=(0, 10), ylim=(0, 1))
PLOT, = sub.plot([],[])
time_text = sub.text(1,1,"",transform = sub.transAxes, ha="right")
t = 0
def init():
PLOT.set_data([],[])
time_text.set_text("")
return PLOT,time_text
def animate(i):
global t
x = np.linspace(0,10,1000)
y = np.exp(- ((x-0.01*i)/(2))**2)/np.sqrt(2*np.pi)
t += 1
PLOT.set_data(x,y)
time_text.set_text("time = "+str(t))
return PLOT, time_text
ani = animation.FuncAnimation(fig, animate, init_func=init, frames=2000, interval=20, blit=True)
plt.show()
그래, 정말 고마워. 쉼표에 관하여 : 예를 들어, 시간 표시를 완료하지 않고 새 plotdata 만 반환하면 : 'return PLOT'은 오류가납니다. 하지만 '리턴 플롯'을 돌려 주면 작동합니다. 그게 왜? – throwaway17434
'PLOT '은'PLOT'에있는 것을 풉니 다. 콘솔에서 이것을 시도해보십시오 :'a, = [1]'. 그런 다음 'a'를 인쇄하십시오. –
좋습니다, 도움이됩니다, 감사합니다 :) – throwaway17434