Repository navigation
ENH: allow animations to be saved as animated GIFs - #1337
Conversation
|
Great work, this should be useful to a lot of people. I'm content to punt on the extra arguments until someone comes up with a use case, because I'm not familiar enough with |
ENH: allow animations to be saved as animated GIFs
|
Great, thanks! |
|
Note to self: Needs at least an entry in whats_new.rst. As for extra arguments, from my personal archive of code, I have found the following arguments to be very valuable:
|
|
In the code, -loop 0 is set by default, and -delay is set appropriately based on the user-specified frame rate. Regarding the dispose argument: where does this appear in the argument list? We could allow setting this through extra_args without overriding the base class One solution would be to add multiple "extra_args" options, but this might be confusing. |
|
Right, I was merely doing a knowledge dump of what I have learned over the Here are some references that may prove useful for anybody who cares enough: |
|
The convert backend could add logic to handle extra_args on its own and put pieces in the appropriate place, I guess. But then again it's been awhile since I wrote the backend code, so I'm not even sure what landmines I may have left that make this non-sensical. |
|
I've managed to create a .gif animation using matplotlib and imagemagick, but haven't managed to then import the created file into the notebook: gives an error: Am I missing something? |
|
The IPython Image tag doesn't support gifs. |
|
I couldn't make it work in Windows 7 (x64 with matplotlib 1.3.1 & ImageMagick installed) After running the sample script from https://gist.github.com/3843162, I got the following error message. Do anybody know why? RuntimeError Traceback (most recent call last)
<ipython-input-2-7b2f7b9edcb4> in <module>()
26 # this is how you save your animation to file:
27 #anim.save('animation.gif', writer='imagemagick_file', fps=30)
---> 28 anim.save('animation.gif', writer='imagemagick', fps=30)
29
30 plt.show()
D:\Python27\lib\site-packages\matplotlib\animation.pyc in save(self, filename, writer, fps, dpi, codec, bitrate, extra_args, metadata, extra_anim, savefig_kwargs)
716 #TODO: Need to see if turning off blit is really necessary
717 anim._draw_next_frame(d, blit=False)
--> 718 writer.grab_frame(**savefig_kwargs)
719
720 # Reconnect signal for first draw if necessary
D:\Python27\lib\site-packages\matplotlib\animation.pyc in grab_frame(self, **savefig_kwargs)
202 # frame format and dpi.
203 self.fig.savefig(self._frame_sink(), format=self.frame_format,
--> 204 dpi=self.dpi, **savefig_kwargs)
205 except RuntimeError:
206 out, err = self._proc.communicate()
D:\Python27\lib\site-packages\matplotlib\figure.pyc in savefig(self, *args, **kwargs)
1419 self.set_frameon(frameon)
1420
-> 1421 self.canvas.print_figure(*args, **kwargs)
1422
1423 if frameon:
D:\Python27\lib\site-packages\matplotlib\backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
2218 orientation=orientation,
2219 bbox_inches_restore=_bbox_inches_restore,
-> 2220 **kwargs)
2221 finally:
2222 if bbox_inches and restore_bbox:
D:\Python27\lib\site-packages\matplotlib\backends\backend_agg.pyc in print_raw(self, filename_or_obj, *args, **kwargs)
495 close = False
496 try:
--> 497 renderer._renderer.write_rgba(filename_or_obj)
498 finally:
499 if close:
RuntimeError: Error writing to file |
|
To update this issue from discussion on the mailing list, it looks like |
|
Might be an issue with piping. Can you try using |
|
The |
|
OK, great |
This is a basic enhancement that allows animations to be saved as animated GIFs, using the ImageMagick
convertutility. It works with either temporary files or piping.A deficiency currently is that extra arguments and options are not passed through: the only option used currently is setting the correct frame rate. Extra options are tough, because they are position dependent. I'm not sure where they should be inserted in the command by default.
A test script can be found here: https://gist.github.com/3843162