35
35
from base64 import encodestring as encodebytes
36
36
import contextlib
37
37
import tempfile
38
+ import warnings
38
39
from matplotlib .cbook import iterable , is_string_like
39
40
from matplotlib .compat import subprocess
40
41
from matplotlib import verbose
@@ -109,6 +110,11 @@ class MovieWriter(object):
109
110
frame_format: string
110
111
The format used in writing frame data, defaults to 'rgba'
111
112
'''
113
+
114
+ # Specifies whether the size of all frames need to be identical
115
+ # i.e. whether we can use savefig.bbox = 'tight'
116
+ frame_size_can_vary = False
117
+
112
118
def __init__ (self , fps = 5 , codec = None , bitrate = None , extra_args = None ,
113
119
metadata = None ):
114
120
'''
@@ -283,6 +289,11 @@ def isAvailable(cls):
283
289
284
290
class FileMovieWriter (MovieWriter ):
285
291
'`MovieWriter` subclass that handles writing to a file.'
292
+
293
+ # In general, if frames are writen to files on disk, it's not important
294
+ # that they all be identically sized
295
+ frame_size_can_vary = True
296
+
286
297
def __init__ (self , * args , ** kwargs ):
287
298
MovieWriter .__init__ (self , * args , ** kwargs )
288
299
self .frame_format = rcParams ['animation.frame_format' ]
@@ -712,29 +723,6 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
712
723
if savefig_kwargs is None :
713
724
savefig_kwargs = {}
714
725
715
- # FIXME: Using 'bbox_inches' doesn't currently work with
716
- # writers that pipe the data to the command because this
717
- # requires a fixed frame size (see Ryan May's reply in this
718
- # thread: [1]). Thus we drop the 'bbox_inches' argument if it
719
- # exists in savefig_kwargs.
720
- #
721
- # [1] (http://matplotlib.1069221.n5.nabble.com/
722
- # Animation-class-let-save-accept-kwargs-which-
723
- # are-passed-on-to-savefig-td39627.html)
724
- #
725
- if 'bbox_inches' in savefig_kwargs :
726
- if not (writer in ['ffmpeg_file' , 'mencoder_file' ] or
727
- isinstance (writer ,
728
- (FFMpegFileWriter , MencoderFileWriter ))):
729
- print ("Warning: discarding the 'bbox_inches' argument in "
730
- "'savefig_kwargs' as it is only currently supported "
731
- "with the writers 'ffmpeg_file' and 'mencoder_file' "
732
- "(writer used: "
733
- "'{0}')." .format (
734
- writer if isinstance (writer , six .string_types )
735
- else writer .__class__ .__name__ ))
736
- savefig_kwargs .pop ('bbox_inches' )
737
-
738
726
# Need to disconnect the first draw callback, since we'll be doing
739
727
# draws. Otherwise, we'll end up starting the animation.
740
728
if self ._first_draw_id is not None :
@@ -778,7 +766,6 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
778
766
extra_args = extra_args ,
779
767
metadata = metadata )
780
768
else :
781
- import warnings
782
769
warnings .warn ("MovieWriter %s unavailable" % writer )
783
770
784
771
try :
@@ -792,6 +779,23 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
792
779
793
780
verbose .report ('Animation.save using %s' % type (writer ),
794
781
level = 'helpful' )
782
+
783
+ # FIXME: Using 'bbox_inches' doesn't currently work with
784
+ # writers that pipe the data to the command because this
785
+ # requires a fixed frame size (see Ryan May's reply in this
786
+ # thread: [1]). Thus we drop the 'bbox_inches' argument if it
787
+ # exists in savefig_kwargs.
788
+ #
789
+ # [1] (http://matplotlib.1069221.n5.nabble.com/
790
+ # Animation-class-let-save-accept-kwargs-which-
791
+ # are-passed-on-to-savefig-td39627.html)
792
+ #
793
+ if 'bbox_inches' in savefig_kwargs and not writer .frame_size_can_vary :
794
+ warnings .warn ("Warning: discarding the 'bbox_inches' argument in "
795
+ "'savefig_kwargs' as it not supported by "
796
+ "{0})." .format (writer .__class__ .__name__ ))
797
+ savefig_kwargs .pop ('bbox_inches' )
798
+
795
799
# Create a new sequence of frames for saved data. This is different
796
800
# from new_frame_seq() to give the ability to save 'live' generated
797
801
# frame information to be saved later.
0 commit comments