Dear Matplotlib Team,
I normally try to animate multiple pictures in the simulation results, but the program always reports errors. I don’t know why. Here are my two kinds of code
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure()
ims = []
for i in range(1,11):
im=plt.imread(str(j)+".png")
ims.append([im])
ani = animation.ArtistAnimation(fig,ims)
ani.save("sin.gif",writer=writer)
plt.show()
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig, ax = plt.subplots()
# ims is a list of lists, each row is a list of artists to draw in the
# current frame; here we are just animating one artist, the image, in
# each frame
ims = []
for j in range(0,10):
im = data[73][j-1].z.plane(z=1e-9).mpl_scalar(cmap='RdBu',filter_field=data[73][j-1].norm,colorbar=False,interpolation='bilinear', animated=True)
if i == 0:
data[73][0].z.plane(z=1e-9).mpl_scalar(cmap='RdBu',filter_field=data[73][j-1].norm,colorbar=False,interpolation='bilinear')
ims.append([im])
ani = animation.ArtistAnimation(fig, ims)
# To save the animation, use e.g.
#
ani.save('demo_6.gif',writer='pillow')
plt.show()
The data.plane.mpl()
inherits the plt.Imshow()
function in Matplotlib. After I run these programs, I report the following error:
AttributeError Traceback (most recent call last)
~/miniconda3/envs/ubermag/lib/python3.8/site-packages/matplotlib/animation.py in saving(self, fig, outfile, dpi, *args, **kwargs)
250 try:
--> 251 yield self
252 finally:
~/miniconda3/envs/ubermag/lib/python3.8/site-packages/matplotlib/animation.py in save(self, filename, writer, fps, dpi, codec, bitrate, extra_args, metadata, extra_anim, savefig_kwargs, progress_callback)
1143 for anim in all_anim:
-> 1144 anim._init_draw() # Clear the initial frame
1145 frame_number = 0
~/miniconda3/envs/ubermag/lib/python3.8/site-packages/matplotlib/animation.py in _init_draw(self)
1506 for artist in f:
-> 1507 artist.set_visible(False)
1508 artist.set_animated(self._blit)
AttributeError: 'NoneType' object has no attribute 'set_visible'
During handling of the above exception, another exception occurred:
IndexError Traceback (most recent call last)
<ipython-input-15-30f3d922a496> in <module>
23 # To save the animation, use e.g.
24 #
---> 25 ani.save('demo_6.gif',writer='pillow')
26
27
~/miniconda3/envs/ubermag/lib/python3.8/site-packages/matplotlib/animation.py in save(self, filename, writer, fps, dpi, codec, bitrate, extra_args, metadata, extra_anim, savefig_kwargs, progress_callback)
1159 progress_callback(frame_number, total_frames)
1160 frame_number += 1
-> 1161 writer.grab_frame(**savefig_kwargs)
1162
1163 def _step(self, *args):
~/miniconda3/envs/ubermag/lib/python3.8/contextlib.py in __exit__(self, type, value, traceback)
129 value = type()
130 try:
--> 131 self.gen.throw(type, value, traceback)
132 except StopIteration as exc:
133 # Suppress StopIteration *unless* it's the same exception that
~/miniconda3/envs/ubermag/lib/python3.8/site-packages/matplotlib/animation.py in saving(self, fig, outfile, dpi, *args, **kwargs)
251 yield self
252 finally:
--> 253 self.finish()
254
255
~/miniconda3/envs/ubermag/lib/python3.8/site-packages/matplotlib/animation.py in finish(self)
552
553 def finish(self):
--> 554 self._frames[0].save(
555 self.outfile, save_all=True, append_images=self._frames[1:],
556 duration=int(1000 / self.fps), loop=0)
IndexError: list index out of range
I don’t know what caused list index out of range
. Can you help me?