我正在尝试使用matplotlib.ArtistAnimation
来动画两个子图。我希望X轴随着动画的进展而增加值,这样动画的总长度是100,但是在任何时候,子图都只给我提供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://stackoverflow.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