Skip to content

Commit 338e1e9

Browse files
authored
Merge pull request #16967 from anntzer/animfallback-pillow
Simplify animation writer fallback.
2 parents e702edd + 4bbca88 commit 338e1e9

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

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)