Reputation: 3
I would like to animate concurrently two groups of patches on my chart. For example Ellipses and Arrows. I can do this separately but not at once.I use pyplot animation, FuncAnimation.
I obtain the following error:
File "/usr/lib/python3/dist-packages/matplotlib/animation.py", line 1199, in _init_draw a.set_animated(self._blit) AttributeError: 'list' object has no attribute 'set_animated'
The code is as follows:
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)
Upvotes: 0
Views: 979
Reputation: 40667
I think your problem is that your animate
function returns a tuple of 2 lists (since self.pedestrians
and self.arrows
are each a List).
The animate function should return a single list of artists.
you should try something like:
def animate(self, i):
(...)
artists = self.pedestrians + self.arrows # concatenate lists of artists
return artists
Upvotes: 1