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

Skip to content

Commit 4bbca88

Browse files
committed
Simplify animation writer fallback.
The fallback now always returns PillowWriter, which is the first registered writer and is always available, so we may just as well be more explicit. (Not all writers support all output formats, but we don't have machinery to select writers based on the output format right now anyways.)
1 parent 84e872d commit 4bbca88

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

lib/matplotlib/animation.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,17 +1087,13 @@ def func(current_frame: int, total_frames: int) -> Any
10871087
# If we have the name of a writer, instantiate an instance of the
10881088
# registered class.
10891089
if isinstance(writer, str):
1090-
if writers.is_available(writer):
1091-
writer = writers[writer](fps, **writer_kwargs)
1092-
else:
1093-
alt_writer = next(iter(writers), None)
1094-
if alt_writer is None:
1095-
raise ValueError("Cannot save animation: no writers are "
1096-
"available. Please install ffmpeg to "
1097-
"save animations.")
1098-
_log.warning("MovieWriter %s unavailable; trying to use %s "
1099-
"instead.", writer, alt_writer)
1100-
writer = alt_writer(fps, **writer_kwargs)
1090+
try:
1091+
writer_cls = writers[writer]
1092+
except RuntimeError: # Raised if not available.
1093+
writer_cls = PillowWriter # Always available.
1094+
_log.warning("MovieWriter %s unavailable; using Pillow "
1095+
"instead.", writer)
1096+
writer = writer_cls(fps, **writer_kwargs)
11011097
_log.info('Animation.save using %s', type(writer))
11021098

11031099
if 'bbox_inches' in savefig_kwargs:

0 commit comments

Comments
 (0)