Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7d1f717

Browse files
committed
MNT: Raise an error for invalid args in animation.save.
When passed arguments that are only used when creating a new MovieWriter instance, raise an error if writer is an existing instance rather than silently ignoring the arguments. Also document the fact that these arguments are invalid in that case.
1 parent fc654e6 commit 7d1f717

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

lib/matplotlib/animation.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -686,28 +686,35 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
686686
687687
*fps* is the frames per second in the movie. Defaults to None,
688688
which will use the animation's specified interval to set the frames
689-
per second.
689+
per second. This argument is only valid if *writer* is not a
690+
:class:`MovieWriter` instance.
690691
691692
*dpi* controls the dots per inch for the movie frames. This combined
692693
with the figure's size in inches controls the size of the movie.
693694
694695
*codec* is the video codec to be used. Not all codecs are supported
695696
by a given :class:`MovieWriter`. If none is given, this defaults to the
696-
value specified by the rcparam `animation.codec`.
697+
value specified by the rcparam `animation.codec`. This argument is only
698+
valid if *writer* is not a :class:`MovieWriter` instance.
697699
698700
*bitrate* specifies the amount of bits used per second in the
699701
compressed movie, in kilobits per second. A higher number means a
700702
higher quality movie, but at the cost of increased file size. If no
701703
value is given, this defaults to the value given by the rcparam
702-
`animation.bitrate`.
704+
`animation.bitrate`. This argument is only valid if *writer* is not a
705+
:class:`MovieWriter` instance.
703706
704707
*extra_args* is a list of extra string arguments to be passed to the
705708
underlying movie utility. The default is None, which passes the
706-
additional arguments in the 'animation.extra_args' rcParam.
709+
additional arguments in the 'animation.extra_args' rcParam. This
710+
argument is only valid if *writer* is not a :class:`MovieWriter`
711+
instance.
707712
708713
*metadata* is a dictionary of keys and values for metadata to include
709714
in the output file. Some keys that may be of use include:
710-
title, artist, genre, subject, copyright, srcform, comment.
715+
title, artist, genre, subject, copyright, srcform, comment. This
716+
argument is only valid if *writer* is not a :class:`MovieWriter`
717+
instance.
711718
712719
*extra_anim* is a list of additional `Animation` objects that should
713720
be included in the saved movie file. These need to be from the same
@@ -720,6 +727,20 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
720727
the individual frames. This can be used to set tight bounding boxes,
721728
for example.
722729
'''
730+
# If the writer is None, use the rc param to find the name of the one
731+
# to use
732+
if writer is None:
733+
writer = rcParams['animation.writer']
734+
elif (not is_string_like(writer) and
735+
any(arg is not None
736+
for arg in (fps, codec, bitrate, extra_args, metadata))):
737+
raise RuntimeError('Passing in values for arguments for arguments '
738+
'fps, codec, bitrate, extra_args, or metadata '
739+
'is not supported when writer is an existing '
740+
'MovieWriter instance. These should instead be '
741+
'passed as arguments when creating the '
742+
'MovieWriter instance.')
743+
723744
if savefig_kwargs is None:
724745
savefig_kwargs = {}
725746

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

738-
# If the writer is None, use the rc param to find the name of the one
739-
# to use
740-
if writer is None:
741-
writer = rcParams['animation.writer']
742-
743759
# Re-use the savefig DPI for ours if none is given
744760
if dpi is None:
745761
dpi = rcParams['savefig.dpi']

0 commit comments

Comments
 (0)