@@ -213,7 +213,13 @@ def grab_frame(self, **savefig_kwargs):
213
213
Grab the image information from the figure and save as a movie frame.
214
214
215
215
All keyword arguments in *savefig_kwargs* are passed on to the
216
- `~.Figure.savefig` call that saves the figure.
216
+ `~.Figure.savefig` call that saves the figure. However, several
217
+ keyword arguments that are supported by `~.Figure.savefig` may not be
218
+ passed as they are controlled by the MovieWriter:
219
+
220
+ - *dpi*, *bbox_inches*: These may not be passed because each frame of the
221
+ animation much be exactly the same size in pixels.
222
+ - *format*: this is controlled by the MovieWriter
217
223
"""
218
224
219
225
@abc .abstractmethod
@@ -351,6 +357,7 @@ def finish(self):
351
357
352
358
def grab_frame (self , ** savefig_kwargs ):
353
359
# docstring inherited
360
+ _validate_grabframe_kwargs (savefig_kwargs )
354
361
_log .debug ('MovieWriter.grab_frame: Grabbing frame.' )
355
362
# Readjust the figure size in case it has been changed by the user.
356
363
# All frames must have the same size to save the movie correctly.
@@ -457,6 +464,7 @@ def _base_temp_name(self):
457
464
def grab_frame (self , ** savefig_kwargs ):
458
465
# docstring inherited
459
466
# Creates a filename for saving using basename and counter.
467
+ _validate_grabframe_kwargs (savefig_kwargs )
460
468
path = Path (self ._base_temp_name () % self ._frame_counter )
461
469
self ._temp_paths .append (path ) # Record the filename for later use.
462
470
self ._frame_counter += 1 # Ensures each created name is unique.
@@ -491,6 +499,7 @@ def setup(self, fig, outfile, dpi=None):
491
499
self ._frames = []
492
500
493
501
def grab_frame (self , ** savefig_kwargs ):
502
+ _validate_grabframe_kwargs (savefig_kwargs )
494
503
buf = BytesIO ()
495
504
self .fig .savefig (
496
505
buf , ** {** savefig_kwargs , "format" : "rgba" , "dpi" : self .dpi })
@@ -747,6 +756,7 @@ def setup(self, fig, outfile, dpi=None, frame_dir=None):
747
756
self ._clear_temp = False
748
757
749
758
def grab_frame (self , ** savefig_kwargs ):
759
+ _validate_grabframe_kwargs (savefig_kwargs )
750
760
if self .embed_frames :
751
761
# Just stop processing if we hit the limit
752
762
if self ._hit_limit :
@@ -1776,3 +1786,11 @@ def _draw_frame(self, framedata):
1776
1786
a .set_animated (self ._blit )
1777
1787
1778
1788
save_count = _api .deprecate_privatize_attribute ("3.7" )
1789
+
1790
+
1791
+ def _validate_grabframe_kwargs (savefig_kwargs ):
1792
+ for k in {'dpi' , 'bbox_inches' , 'format' }:
1793
+ if k in savefig_kwargs :
1794
+ raise TypeError (
1795
+ f"grab_frame got an unexpected keyword argument { k !r} "
1796
+ )
0 commit comments