我想在我的图表上同时动画两组补丁。例如椭圆和箭头。我可以分开做,但不能一次完成,我使用pyplot动画,FuncAnimation。在
我得到以下错误:
文件“/usr/lib/python3/dist packages/matplotlib/动画.py“,第1199行,在初始绘制中 a、 设置动画(self.\u blit) AttributeError:“list”对象没有“set\u animated”属性
代码如下:
def initiate_chart(self, axes, title='Layout'):
self.title = title
plt.title = self.title
self.ax = plt.axes(xlim=(axes[0]['xmin'], axes[0]['xmax']), ylim=(axes[0]['ymin'], axes[0]['ymax']))
elipses = [Ellipse(i, width=0.6, height=0.3, angle=0) for i in self.trajectory[0]]
arrows = [Arrow(x, y, self.velocities[0][i][0], self.velocities[0][i][1])
for (i, (x, y)) in enumerate(self.trajectory[0])]
[self.pedestrians.append(self.ax.add_patch(elipses[i])) for i in range(len(elipses))]
[self.arrows.append(self.ax.add_patch(arrows[i])) for i in range(len(arrows))]
def init_animation(self):
[self.pedestrians[i].set_visible(True) for i in range(len(self.pedestrians))]
[self.arrows[i].set_visible(True) for i in range(len(self.arrows))]
return self.pedestrians, self.arrows
def animate(self, i):
self.arrows = []
for j in range(len(self.pedestrians)):
angle = degrees(atan2(self.trajectory[i][j][0], self.trajectory[i][j][1]))
self.pedestrians[j].center = self.trajectory[i][j]
self.pedestrians[j].angle = angle
self.arrows.append(self.ax.add_patch(Arrow(self.trajectory[i][j][0], self.trajectory[i][j][1],
self.velocities[i][j][0], self.velocities[i][j][1], width=0.5)))
return self.pedestrians, self.arrows
def do_animation(self, n_frames, n_interval):
anim = animation.FuncAnimation(self.fig, self.animate, init_func=self.init_animation, frames=n_frames,
interval=n_interval, blit=True)
我认为您的问题是}都是一个列表)。在
animate
函数返回一个由2个列表组成的元组(因为self.pedestrians
和{animate函数应该返回一个艺术家列表。在
你应该尝试一下:
相关问题 更多 >
编程相关推荐