1
votes

this is my first time posting here. I'm running this code which is a matplotlib (version 3.2.1) animation example, so it was supposed to work fine.

import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
plt.rcParams['animation.ffmpeg_path'] = '/opt/local/bin/ffmpeg'

# First set up the figure, the axis, and the plot element we want to animate
fig = plt.figure()
ax = plt.axes(xlim=(0, 2), ylim=(-2, 2))
line, = ax.plot([], [], lw=2)

# initialization function: plot the background of each frame
def init():
    line.set_data([], [])
    return line

# animation function.  This is called sequentially
def animate(i):
    x = np.linspace(0, 2, 1000)
    y = np.sin(2 * np.pi * (x - 0.01 * i))
    line.set_data(x, y)
    return line,

# call the animator.  blit=True means only re-draw the parts that have changed.
anim = animation.FuncAnimation(fig, animate, init_func=init,
                               frames=200, interval=20, blit=True)

# save the animation as an mp4.  This requires ffmpeg or mencoder to be
# installed.  The extra_args ensure that the x264 codec is used, so that
# the video can be embedded in html5.  You may need to adjust this for
# your system: for more information, see
# http://matplotlib.sourceforge.net/api/animation_api.html
anim.save('basic_animation.mp4', fps=30, extra_args=['-vcodec', 'libx264'])

plt.show()

However, I'm getting this error:

Traceback (most recent call last): File "matplotlib_animation.py", line 42, in anim.save('basic_animation.mp4', fps=30, extra_args=['-vcodec', 'libx264']) File "/home/leonardo/.local/lib/python3.6/site-packages/matplotlib/animation.py", line 1102, in save alt_writer = next(writers, None) TypeError: 'MovieWriterRegistry' object is not an iterator /home/leonardo/.local/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3.py:195: Warning: Source ID 8 was not found when attempting to remove it GLib.source_remove(self._idle_draw_id)

Any ideas will be very appreciated.

1
Few Checks : 1. Can you see your animation using plt.show() alone ( after commenting your anim.save() line) ? 2. Which version of python are you using? Is this problem reproducible using some previous version matplotlib older than 3.2 ? github.com/matplotlib/matplotlib/issues/16965 - AshlinJP
Thank you for your reply. 1. Yes, I can check my animation. 2. Python 3.6.9. I don't know if this problem is reproducible in older versions. I've seen this issue on github, but up until now there haven't been any updates. - Leonardo Araujo

1 Answers

1
votes

It's a known bug in the latest version of matplotlib; it will be fixed in the next point release (#16965).From github issse: https://github.com/matplotlib/matplotlib/issues/17097