matplotlib.ArtistAnimation
을 사용하여 두 개의 부 그림을 애니메이션화하려고합니다. 애니메이션의 총 길이가 100이되도록 x 축의 값이 증가하기를 원하지만 언제든지 서브 플로트는 0-24의 시간 값을 제시하고 나면 최대 100까지 반복합니다.matplotlib 애니메이션을 사용하여 x 축 값 업데이트
큰 예제는 here입니다. 링크는 FuncAnimation
을 사용하고 plot().axes.set_xlim()
을 사용하고 x 값을 증가시켜 롤링 방식으로 x 축 레이블을 업데이트합니다. 코드는 제공된 링크의 YouTube 동영상 아래 링크를 통해 제공됩니다.
이러한 결과를 복제하려는 시도를 보여 주지만 x- 제한은 시간이 증가하는 대신 최종 값을 대신하는 것처럼 보이는 아래 코드를 추가했습니다. 나는 또한 서브 플롯에서 볼 수있는 창에서 값을 플로팅하여 x 축 값을 증가시키지 않고 (축과 대조적으로) 솔루션을 증가 시키려고 시도했습니다. 또한 자동 크기 조정을 구현하려고 시도했지만 x 축은 여전히 업데이트되지 않습니다.
나는 또한 실질적으로 동일한 문제인 this question을 발견했지만 그 질문에는 결코 대답하지 않았습니다.
import matplotlib.pylab as plt
import matplotlib.animation as anim
import numpy as np
#create image with format (time,x,y)
image = np.random.rand(100,10,10)
#setup figure
fig = plt.figure()
ax1=fig.add_subplot(1,2,1)
ax2=fig.add_subplot(1,2,2)
#set up viewing window (in this case the 25 most recent values)
repeat_length = (np.shape(image)[0]+1)/4
ax2.set_xlim([0,repeat_length])
#ax2.autoscale_view()
ax2.set_ylim([np.amin(image[:,5,5]),np.amax(image[:,5,5])])
#set up list of images for animation
ims=[]
for time in xrange(np.shape(image)[0]):
im = ax1.imshow(image[time,:,:])
im2, = ax2.plot(image[0:time,5,5],color=(0,0,1))
if time>repeat_length:
lim = ax2.set_xlim(time-repeat_length,time)
ims.append([im, im2])
#run animation
ani = anim.ArtistAnimation(fig,ims, interval=50,blit=False)
plt.show()
가 난 단지 두 번째 부가 적 줄거리 (ax2
)는 x 축 값을 업데이트 할 :
여기 내 코드입니다.
도움을 주시면 감사하겠습니다.
http://itackoverflow.com/questions/17558096/animated-title-in-matplotlib/17562747#17562747 <- blit에 라벨을 업데이트하려면 – tacaswell
http://stackoverflow.com/questions/17888593/display-sequence -of-images-using-matplotlib – tacaswell
blit을 사용할 때 애니메이션이 실행되지 않는다. 이유는 확실하지 않다. – abradd