8000 ArtistAnimation for multiple artists in one frame · Issue #18381 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
ArtistAnimation for multiple artists in one frame #18381
Closed
@gfadini

Description

@gfadini

Hello,
I'm trying to use the ArtistAnimation to animate a plot, now if I simply use one plotting function I can follow the examples of the documentation. If I try to add more than one plot to the same artist collection (to be shown in the same frame), I get an error and a static figure with the superposition of all the artists.

I attach a minimal example, ideally I would like to have the following things as outcome:

  • shape of the plot to be changing with the time frame t
  • data plotted marked by points and line
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig = plt.figure()

x = np.arange(-9, 10)
y = np.arange(-9, 10).reshape(-1, 1)
ims = []
for t in np.arange(15):
    ims.append((plt.plot(x+t,y+t**2), plt.scatter(x+t,y+t**2)))

im_ani = animation.ArtistAnimation(fig, ims, interval=50, repeat_delay=3000,
                                   blit=True)

plt.show()

However I get an error and the plot is not an animation anymore if I also try to add the scatter of points
Figure_1

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/matplotlib/cbook/__init__.py", line 224, in process
    func(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/matplotlib/animation.py", line 959, in _start
    self._init_draw()
  File "/usr/lib/python3.8/site-packages/matplotlib/animation.py", line 1491, in _init_draw
    artist.set_visible(False)
AttributeError: 'list' object has no attribute 'set_visible'
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/matplotlib/cbook/__init__.py", line 224, in process
    func(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/matplotlib/animation.py", line 1259, in _on_resize
    self._init_draw()
  File "/usr/lib/python3.8/site-packages/matplotlib/animation.py", line 1491, in _init_draw
    artist.set_visible(False)
AttributeError: 'list' object has no attribute 'set_visible'

Since the documentation example doesn't cover this case and to me the line here sounds pretty vague about the collection of artists to be used, can I have some help?

artistslist
Each list entry is a collection of artists that are made visible on the corresponding frame. Other artists are made invisible.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0