ArtistAnimation with 3D plotting?

I have a list of files, each of which stores locations of particles at different times. I’d like to create an animation that shows the particles’ movement in time. I tried to use matplotlib.animation.ArtistAnimation as follows:

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
artists = []
for evolve_idx in range(TOT_STEPS):
    _, data = pl.readdump(positions_dir + str(evolve_idx) + ".txt")
    container = ax.scatter(data[10:-10:10, :, 0], data[10:-10:10, :, 1], data[10:-10:10, :, 2])
    artists.append(container)

ani = animation.ArtistAnimation(fig=fig, artists=artists, interval=400)
plt.show()

Where pl.readdump is a function that reads the data from these text files. I get the error:

TypeError: 'Path3DCollection' object is not iterable

So I guess that’s because ax.scatter doesn’t return an object of instance Artist, because it’s a 3d plot.

Hence I wonder - is there a way to use ArtistAnimation with ax.scatter for 3D plotting?

I think I can use FuncAnimation with a an updating function that runs plot.remove() or ax.clear(), as done here, but I’m not sure if that’s the only way.

Help will be appreciated!

The ArtistAnimation docs say that artists should be:

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

However, each entry that you have provided is a single Artist. Instead, it should be wrapped in a list or tuple.