Skip to content

Animation error handling (Fixes #6416) #6441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 17, 2016
Merged
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
57 changes: 36 additions & 21 deletions lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,14 @@ def grab_frame(self, **savefig_kwargs):
# frame format and dpi.
self.fig.savefig(self._frame_sink(), format=self.frame_format,
dpi=self.dpi, **savefig_kwargs)
except RuntimeError:
except (RuntimeError, IOError) as e:
out, err = self._proc.communicate()
verbose.report('MovieWriter -- Error '
'running proc:\n%s\n%s' % (out,
err), level='helpful')
raise
raise IOError('Error saving animation to file (cause: {0}) '
'Stdout: {1} StdError: {2}. It may help to re-run '
'with --verbose-debug.'.format(e, out, err))

def _frame_sink(self):
'Returns the place to which frames should be written.'
Expand Down Expand Up @@ -684,13 +686,28 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
If nothing is passed, the value of the rcparam `animation.writer` is
used.

*dpi* controls the dots per inch for the movie frames. This combined
with the figure's size in inches controls the size of the movie.

*savefig_kwargs* is a dictionary containing keyword arguments to be
passed on to the 'savefig' command which is called repeatedly to save
the individual frames. This can be used to set tight bounding boxes,
for example.

*extra_anim* is a list of additional `Animation` objects that should
be included in the saved movie file. These need to be from the same
`matplotlib.Figure` instance. Also, animation frames will just be
simply combined, so there should be a 1:1 correspondence between
the frames from the different animations.

These remaining arguments are used to construct a :class:`MovieWriter`
instance when necessary and are only considered valid if *writer* is
not a :class:`MovieWriter` instance.

*fps* is the frames per second in the movie. Defaults to None,
which will use the animation's specified interval to set the frames
per second.

*dpi* controls the dots per inch for the movie frames. This combined
with the figure's size in inches controls the size of the movie.

*codec* is the video codec to be used. Not all codecs are supported
by a given :class:`MovieWriter`. If none is given, this defaults to the
value specified by the rcparam `animation.codec`.
Expand All @@ -708,18 +725,21 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
*metadata* is a dictionary of keys and values for metadata to include
in the output file. Some keys that may be of use include:
title, artist, genre, subject, copyright, srcform, comment.

*extra_anim* is a list of additional `Animation` objects that should
be included in the saved movie file. These need to be from the same
`matplotlib.Figure` instance. Also, animation frames will just be
simply combined, so there should be a 1:1 correspondence between
the frames from the different animations.

*savefig_kwargs* is a dictionary containing keyword arguments to be
passed on to the 'savefig' command which is called repeatedly to save
the individual frames. This can be used to set tight bounding boxes,
for example.
'''
# If the writer is None, use the rc param to find the name of the one
# to use
if writer is None:
writer = rcParams['animation.writer']
elif (not is_string_like(writer) and
any(arg is not None
for arg in (fps, codec, bitrate, extra_args, metadata))):
raise RuntimeError('Passing in values for arguments for arguments '
'fps, codec, bitrate, extra_args, or metadata '
'is not supported when writer is an existing '
'MovieWriter instance. These should instead be '
'passed as arguments when creating the '
'MovieWriter instance.')

if savefig_kwargs is None:
savefig_kwargs = {}

Expand All @@ -735,11 +755,6 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
# Convert interval in ms to frames per second
fps = 1000. / self._interval

# If the writer is None, use the rc param to find the name of the one
# to use
if writer is None:
writer = rcParams['animation.writer']

# Re-use the savefig DPI for ours if none is given
if dpi is None:
dpi = rcParams['savefig.dpi']
Expand Down