I have a very simple code from the matplotlib example:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig, ax = plt.subplots()
line, = ax.plot(np.random.rand(10))
ax.set_ylim(0, 1)
def update(data):
line.set_ydata(data)
return line,
def data_gen():
while True: yield np.random.rand(10)
ani = animation.FuncAnimation(fig, update, data_gen, interval=1000)
anim.save('basic_animation.mp4', fps=30)
plt.show()
Everything is right if I do not use anim.save() function. However, when I want to save it, it would report:
IOError Traceback (most recent call last)
<ipython-input-6-8948bc3b3f5c> in <module>()
16
17 ani = animation.FuncAnimation(fig, update, data_gen, interval=1000)
---> 18 anim.save('basic_animation.mp4', fps=30)
19 plt.show()
....(traceback details are omitted here)
/home/xin/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in print_raw(self, filename_or_obj, *args, **kwargs)
517 close = False
518 try:
--> 519 fileobj.write(renderer._renderer.buffer_rgba())
520 finally:
521 if close:
IOError: [Errno 32] Broken pipe
How can I fix it? Or are there any other ways to save animation to a file?
Supplement: To install ffmpeg, I just run: conda install -c https://conda.anaconda.org/mutirri ffmpeg
Get it solved by myself! I use conda install to get ffmpeg but when using ffmpeg --version will always say that:
libssl.so.10: cannot open shared object file: No such file or directory
so I use:
sudo ln -s /home/xin/anaconda2/lib/libssl.so.1.0.0 libssl.so.10
Then get similar problem about libcrypto.so.10, so I use:
sudo ln -s /home/xin/anaconda2/lib/libcrypto.so.1.0.0 libcrypto.so.10
The two files are in /lib/x86_64-linux-gnu.
Now things work!! I know some people also have similar problems, so I record it here.
In future, if need to remove the link:
cd /lib/x86_64-linux-gnu
sudo unlink libssl.so.10
sudo unlink libcrypto.so.10
I had this problem too. Specifying writer='imagemagick'
worked for me.
anim.save('basic_animation.mp4', fps=30, writer='imagemagick')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With