|
31 | 31 | import warnings
|
32 | 32 |
|
33 | 33 | import numpy as np
|
| 34 | +from PIL import Image |
34 | 35 |
|
35 | 36 | import matplotlib as mpl
|
36 | 37 | from matplotlib._animation_data import (
|
@@ -296,8 +297,11 @@ def __init__(self, fps=5, codec=None, bitrate=None, extra_args=None,
|
296 | 297 |
|
297 | 298 | super().__init__(fps=fps, metadata=metadata, codec=codec,
|
298 | 299 | bitrate=bitrate)
|
299 |
| - |
300 |
| - self.frame_format = 'rgba' |
| 300 | + # The rcParam only applies to FileMovieWriters, but should be read here |
| 301 | + # because setting to frame_format to 'rgba' would otherwise spuriously |
| 302 | + # warn that that format is unsupported e.g. for FFMpegFileWriter. |
| 303 | + self.frame_format = (mpl.rcParams['animation.frame_format'] |
| 304 | + if isinstance(self, FileMovieWriter) else 'rgba') |
301 | 305 | self.extra_args = extra_args
|
302 | 306 |
|
303 | 307 | def _adjust_frame_size(self):
|
@@ -395,9 +399,6 @@ class FileMovieWriter(MovieWriter):
|
395 | 399 |
|
396 | 400 | This must be sub-classed to be useful.
|
397 | 401 | """
|
398 |
| - def __init__(self, *args, **kwargs): |
399 |
| - super().__init__(*args, **kwargs) |
400 |
| - self.frame_format = mpl.rcParams['animation.frame_format'] |
401 | 402 |
|
402 | 403 | @cbook._delete_parameter("3.3", "clear_temp")
|
403 | 404 | def setup(self, fig, outfile, dpi=None, frame_prefix=None,
|
@@ -467,6 +468,10 @@ def frame_format(self, frame_format):
|
467 | 468 | if frame_format in self.supported_formats:
|
468 | 469 | self._frame_format = frame_format
|
469 | 470 | else:
|
| 471 | + cbook._warn_external( |
| 472 | + f"Ignoring file format {frame_format!r} which is not " |
| 473 | + f"supported by {type(self).__name__}; using " |
| 474 | + f"{self.supported_formats[0]} instead.") |
470 | 475 | self._frame_format = self.supported_formats[0]
|
471 | 476 |
|
472 | 477 | def _base_temp_name(self):
|
@@ -529,7 +534,6 @@ def setup(self, fig, outfile, dpi=None):
|
529 | 534 | self._frames = []
|
530 | 535 |
|
531 | 536 | def grab_frame(self, **savefig_kwargs):
|
532 |
| - from PIL import Image |
533 | 537 | buf = BytesIO()
|
534 | 538 | self.fig.savefig(
|
535 | 539 | buf, **{**savefig_kwargs, "format": "rgba", "dpi": self.dpi})
|
@@ -629,8 +633,7 @@ class FFMpegFileWriter(FFMpegBase, FileMovieWriter):
|
629 | 633 | Frames are written to temporary files on disk and then stitched
|
630 | 634 | together at the end.
|
631 | 635 | """
|
632 |
| - supported_formats = ['png', 'jpeg', 'ppm', 'tiff', 'sgi', 'bmp', |
633 |
| - 'pbm', 'raw', 'rgba'] |
| 636 | + supported_formats = ['png', 'jpeg', 'ppm', 'tiff', 'sgi', 'bmp', 'pbm'] |
634 | 637 |
|
635 | 638 | def _args(self):
|
636 | 639 | # Returns the command line parameters for subprocess to use
|
@@ -744,14 +747,15 @@ class ImageMagickFileWriter(ImageMagickBase, FileMovieWriter):
|
744 | 747 |
|
745 | 748 | Frames are written to temporary files on disk and then stitched
|
746 | 749 | together at the end.
|
747 |
| -
|
748 | 750 | """
|
749 | 751 |
|
750 |
| - supported_formats = ['png', 'jpeg', 'ppm', 'tiff', 'sgi', 'bmp', |
751 |
| - 'pbm', 'raw', 'rgba'] |
| 752 | + supported_formats = ['png', 'jpeg', 'ppm', 'tiff', 'sgi', 'bmp', 'pbm', |
| 753 | + 'rgba'] |
752 | 754 |
|
753 | 755 | def _args(self):
|
754 |
| - return ([self.bin_path(), '-delay', str(self.delay), '-loop', '0', |
| 756 | + return ([self.bin_path(), |
| 757 | + '-size', '%ix%i' % self.frame_size, '-depth', '8', |
| 758 | + '-delay', str(self.delay), '-loop', '0', |
755 | 759 | '%s*.%s' % (self.temp_prefix, self.frame_format)]
|
756 | 760 | + self.output_args)
|
757 | 761 |
|
|
0 commit comments