Animation with matplotlib format "rgba" is not supported "
I am trying to do animation with matplotlib using examples from here . At first the problem was that ffmpeg was not installed, so I installed that from macports but didn't say "rgba" is not supported. Error message:
File "Plot_shocktube1D.py", line 85, in <module>
animDensity.save(densityAnimationName, extra_args=['-vcodec', 'libx264']) #, writer=movWriter)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/animation.py", line 615, in save
writer.grab_frame()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/animation.py", line 199, in grab_frame
dpi=self.dpi)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/figure.py", line 1363, in savefig
self.canvas.print_figure(*args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 2012, in print_figure
print_method = self._get_print_method(format)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 1953, in _get_print_method
'%s.' % (format, ', '.join(formats)))
ValueError: Format "rgba" is not supported.
Supported formats: bmp, emf, eps, gif, jpeg, jpg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff.
Now, after some struggle, I install FFMpegWriter
using png
instead rgba
, but now I am getting new errors ...
movWriter = anim.FFMpegWriter(fps=5, codec=None, bitrate=None, extra_args=None, metadata=None)
movWriter.frame_format = 'jpg'
animDensity = anim.FuncAnimation(fig, animateDensity, frames=10, interval=100, blit=True)
animDensity.save(densityAnimationName, extra_args=['-vcodec', 'libx264'], writer=movWriter)
with mistakes:
File "Plot_shocktube1D.py", line 85, in <module>
animDensity.save(densityAnimationName, extra_args=['-vcodec', 'libx264'], writer=movWriter)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/animation.py", line 615, in save
writer.grab_frame()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/animation.py", line 199, in grab_frame
dpi=self.dpi)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/figure.py", line 1363, in savefig
self.canvas.print_figure(*args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 2093, in print_figure
**kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 326, in print_jpg
self._print_bitmap(filename, *args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 319, in _print_bitmap
self.write_bitmap(filename, width, height, dpi)
ValueError: Unknown file type
I'm under the impression that I just don't have something installed that I need ... Usually macports sets me up with everything and I'm not really sure where to look. Any help would be greatly appreciated.
source to share
This use () statement did not help me, but I ran into the same errors as for the second part of the main example of matplotlib animation running in IPython. I used macports to install ffmpeg and then I got the same rgba that didn't support the warning (even though rgba appears in the list of supported formats!).
Anyway, I found that if I used the explicated FFMpegFileWriter (not just FFMpegWriter) everything was fine and the rgba problem was gone and I got a useful m4v file:
import matplotlib.animation as animation fig2 = plt.figure() x = np.arange(-9, 10) y = np.arange(-9, 10).reshape(-1, 1) base = np.hypot(x, y) ims = [] for add in np.arange(15): ims.append((plt.pcolor(x, y, base + add, norm=plt.Normalize(0, 30)),)) im_ani = animation.ArtistAnimation(fig2, ims, interval=50, repeat_delay=3000, blit=True) im_ani.save('im.m4v', writer=animation.FFMpegFileWriter(), metadata={'artist':'Guido'})
source to share