Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,41 @@ def _args(self):
self.fps)] + self.output_args


# Base class for animated GIFs with convert utility
class ImageMagickBase:
exec_key = 'animation.convert_path'
args_key = 'animation.convert_args'

@property
def delay(self):
return 100. / self.fps

@property
def output_args(self):
return [self.outfile]


@writers.register('imagemagick')
class ImageMagickWriter(MovieWriter, ImageMagickBase):
def _args(self):
return ([self.bin_path(),
'-size', '%ix%i' % self.frame_size, '-depth', '8',
'-delay', str(self.delay), '-loop', '0',
'%s:-' % self.frame_format]
+ self.output_args)


@writers.register('imagemagick_file')
class ImageMagickFileWriter(FileMovieWriter, ImageMagickBase):
supported_formats = ['png', 'jpeg', 'ppm', 'tiff', 'sgi', 'bmp',
'pbm', 'raw', 'rgba']

def _args(self):
return ([self.bin_path(), '-delay', str(self.delay), '-loop', '0',
'%s*.%s' % (self.temp_prefix, self.frame_format)]
+ self.output_args)


class Animation(object):
'''
This class wraps the creation of an animation using matplotlib. It is
Expand Down Expand Up @@ -512,7 +547,7 @@ def _stop(self, *args):
self.event_source = None

def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
bitrate=None, extra_args=None, metadata=None, extra_anim=None):
bitrate=None, extra_args=None, metadata=None, extra_anim=None):
'''
Saves a movie file by drawing every frame.

Expand Down
5 changes: 4 additions & 1 deletion lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ def validate_hinting(s):
['xelatex', 'lualatex', 'pdflatex'])

validate_movie_writer = ValidateInStrings('animation.writer',
['ffmpeg', 'ffmpeg_file', 'mencoder', 'mencoder_file'])
['ffmpeg', 'ffmpeg_file', 'mencoder', 'mencoder_file',
'imagemagick', 'imagemagick_file'])

validate_movie_frame_fmt = ValidateInStrings('animation.frame_format',
['png', 'jpeg', 'tiff', 'raw', 'rgba'])
Expand Down Expand Up @@ -621,6 +622,8 @@ def __call__(self, s):
'animation.ffmpeg_args' : ['', validate_stringlist], # Additional arguments for ffmpeg movie writer (using pipes)
'animation.mencoder_path' : ['mencoder', str], # Path to FFMPEG binary. If just binary name, subprocess uses $PATH.
'animation.mencoder_args' : ['', validate_stringlist], # Additional arguments for mencoder movie writer (using pipes)
'animation.convert_path' : ['convert', str], # Path to convert binary. If just binary name, subprocess uses $PATH
'animation.convert_args' : ['', validate_stringlist], # Additional arguments for mencoder movie writer (using pipes)
}

if __name__ == '__main__':
Expand Down