我试图用来matplotlib.ArtistAnimation动画两个子图.我希望随着动画的进行,x轴的值增加,这样动画的总长度就是100,但是在任何时候,子图只向我显示0-24的时间值,然后迭代到100.
这里给出了一个很好的例子.该链接使用FuncAnimation并plot().axes.set_xlim()递增x值以滚动方式使用和更新x轴标签.该代码可通过所提供链接中YouTube视频下方的链接获取.
我在下面附加了代码,显示了我尝试复制这些结果但x限制似乎采用了它们的最终值而不是随时间递增.我还尝试通过仅绘制将在子图中看到的窗口中的值来递增解(而不是轴),但不会增加x轴值.我也试图实现自动缩放,但x轴仍然没有更新.
我也发现这个问题实际上是同一个问题,但问题从来没有得到解答.
这是我的代码:
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 …Run Code Online (Sandbox Code Playgroud) 我正在进行图像分析,我想创建最终结果的动画,其中包括2D数据的时间序列和单个像素的时间序列图,使得1D绘图随着2D动画的进展而更新.然后将它们并排放置在子图中.下面的链接有一个最终结果的图像,理想情况下是动画的.

我一直收到错误:AttributeError:'list'对象没有属性'set_visible'.我用Google搜索了(就像你一样)并偶然发现了http://matplotlib.1069221.n5.nabble.com/Matplotlib-1-1-0-animation-vs-contour-plots-td18703.html其中一个家伙打了一拳用于设置set_visible属性的代码.不幸的是,plot命令似乎没有这样的属性,所以我不知道如何制作动画.我已经将猴子补丁包含在下面的最小工作示例中(注释掉了)以及第二个"im2",它也被注释掉了,它应该适用于任何试图运行代码的人.显然它会给你两个2D绘图动画.最小的工作示例如下:
#!/usr/bin/env python
import matplotlib.pyplot as plt
import matplotlib.animation as anim
import numpy as np
import types
#create image with format (time,x,y)
image = np.random.rand(10,10,10)
image2 = np.random.rand(10,10,10)
#setup figure
fig = plt.figure()
ax1=fig.add_subplot(1,2,1)
ax2=fig.add_subplot(1,2,2)
#set up list of images for animation
ims=[]
for time in xrange(np.shape(image)[1]):
im = ax1.imshow(image[time,:,:])
# im2 = ax2.imshow(image2[time,:,:])
im2 = ax2.plot(image[0:time,5,5])
# def setvisible(self,vis):
# for c in self.collections: c.set_visible(vis)
# im2.set_visible = types.MethodType(setvisible,im2,None)
# im2.axes = plt.gca()
ims.append([im, im2])
#run …Run Code Online (Sandbox Code Playgroud)