2929# * http://pymedia.org/
3030# * libmng (produces swf) python wrappers: https://github.com/libming/libming
3131# * Wrap x264 API:
32- # http://stackoverflow.com/questions/2940671/how-to-encode-series-of-images-into-h264-using-x264-api-c-c
32+
33+ # (http://stackoverflow.com/questions/2940671/
34+ # how-to-encode-series-of-images-into-h264-using-x264-api-c-c )
3335
3436
3537# A registry for available MovieWriter classes
@@ -83,7 +85,7 @@ class MovieWriter(object):
8385 The format used in writing frame data, defaults to 'rgba'
8486 '''
8587 def __init__ (self , fps = 5 , codec = None , bitrate = None , extra_args = None ,
86- metadata = None ):
88+ metadata = None ):
8789 '''
8890 Construct a new MovieWriter object.
8991
@@ -199,11 +201,12 @@ def grab_frame(self, **savefig_kwargs):
199201 # Tell the figure to save its data to the sink, using the
200202 # frame format and dpi.
201203 self .fig .savefig (self ._frame_sink (), format = self .frame_format ,
202- dpi = self .dpi , ** savefig_kwargs )
204+ dpi = self .dpi , ** savefig_kwargs )
203205 except RuntimeError :
204206 out , err = self ._proc .communicate ()
205- verbose .report ('MovieWriter -- Error running proc:\n %s\n %s' % (out ,
206- err ), level = 'helpful' )
207+ verbose .report ('MovieWriter -- Error '
208+ 'running proc:\n %s\n %s' % (out ,
209+ err ), level = 'helpful' )
207210 raise
208211
209212 def _frame_sink (self ):
@@ -217,10 +220,10 @@ def _args(self):
217220 def cleanup (self ):
218221 'Clean-up and collect the process used to write the movie file.'
219222 out , err = self ._proc .communicate ()
220- verbose .report ('MovieWriter -- Command stdout: \n %s' % out ,
221- level = 'debug' )
222- verbose .report ('MovieWriter -- Command stderr: \n %s' % err ,
223- level = 'debug' )
223+ verbose .report ('MovieWriter -- '
224+ 'Command stdout: \n %s' % out , level = 'debug' )
225+ verbose .report ('MovieWriter -- '
226+ 'Command stderr: \n %s' % err , level = 'debug' )
224227
225228 @classmethod
226229 def bin_path (cls ):
@@ -238,8 +241,10 @@ def isAvailable(cls):
238241 running the commandline tool.
239242 '''
240243 try :
241- subprocess .Popen (cls .bin_path (), shell = False ,
242- stdout = subprocess .PIPE , stderr = subprocess .PIPE )
244+ subprocess .Popen (cls .bin_path (),
245+ shell = False ,
246+ stdout = subprocess .PIPE ,
247+ stderr = subprocess .PIPE )
243248 return True
244249 except OSError :
245250 return False
@@ -307,7 +312,7 @@ def _frame_sink(self):
307312 self ._temp_names .append (fname )
308313 verbose .report (
309314 'FileMovieWriter.frame_sink: saving frame %d to fname=%s' %
310- (self ._frame_counter , fname ),
315+ (self ._frame_counter , fname ),
311316 level = 'debug' )
312317 self ._frame_counter += 1 # Ensures each created name is 'unique'
313318
@@ -325,8 +330,8 @@ def finish(self):
325330 # the process here, rather than having an open pipe.
326331 if self ._proc .returncode :
327332 raise RuntimeError ('Error creating movie, return code: '
328- + str (self ._proc .returncode )
329- + ' Try running with --verbose-debug' )
333+ + str (self ._proc .returncode )
334+ + ' Try running with --verbose-debug' )
330335
331336 def cleanup (self ):
332337 MovieWriter .cleanup (self )
@@ -405,6 +410,7 @@ class AVConvBase(FFMpegBase):
405410class AVConvWriter (AVConvBase , FFMpegWriter ):
406411 pass
407412
413+
408414# Combine AVConv options with file-based writing
409415@writers .register ('avconv_file' )
410416class AVConvFileWriter (AVConvBase , FFMpegFileWriter ):
@@ -420,7 +426,7 @@ class MencoderBase:
420426 # Mencoder only allows certain keys, other ones cause the program
421427 # to fail.
422428 allowed_metadata = ['name' , 'artist' , 'genre' , 'subject' , 'copyright' ,
423- 'srcform' , 'comment' ]
429+ 'srcform' , 'comment' ]
424430
425431 # Mencoder mandates using name, but 'title' works better with ffmpeg.
426432 # If we find it, just put it's value into name
@@ -439,8 +445,8 @@ def output_args(self):
439445 args .extend (self .extra_args )
440446 if self .metadata :
441447 args .extend (['-info' , ':' .join ('%s=%s' % (k , v )
442- for k , v in self .metadata .items ()
443- if k in self .allowed_metadata )])
448+ for k , v in self .metadata .items ()
449+ if k in self .allowed_metadata )])
444450 return args
445451
446452
@@ -451,9 +457,9 @@ def _args(self):
451457 # Returns the command line parameters for subprocess to use
452458 # mencoder to create a movie
453459 return [self .bin_path (), '-' , '-demuxer' , 'rawvideo' , '-rawvideo' ,
454- ('w=%i:h=%i:' % self .frame_size +
455- 'fps=%i:format=%s' % (self .fps ,
456- self .frame_format ))] + self .output_args
460+ ('w=%i:h=%i:' % self .frame_size +
461+ 'fps=%i:format=%s' % (self .fps ,
462+ self .frame_format ))] + self .output_args
457463
458464
459465# Combine Mencoder options with temp file-based writing
@@ -465,10 +471,10 @@ def _args(self):
465471 # Returns the command line parameters for subprocess to use
466472 # mencoder to create a movie
467473 return [self .bin_path (),
468- 'mf://%s*.%s' % (self .temp_prefix , self .frame_format ),
469- '-frames' , str (self ._frame_counter ), '-mf' ,
470- 'type=%s:fps=%d' % (self .frame_format ,
471- self .fps )] + self .output_args
474+ 'mf://%s*.%s' % (self .temp_prefix , self .frame_format ),
475+ '-frames' , str (self ._frame_counter ), '-mf' ,
476+ 'type=%s:fps=%d' % (self .frame_format ,
477+ self .fps )] + self .output_args
472478
473479
474480# Base class for animated GIFs with convert utility
@@ -622,21 +628,26 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
622628 if savefig_kwargs is None :
623629 savefig_kwargs = {}
624630
625- # FIXME: Using 'bbox_inches' doesn't currently work with writers that pipe
626- # the data to the command because this requires a fixed frame size (see
627- # Ryan May's reply in this thread: [1]). Thus we drop the 'bbox_inches'
628- # argument if it exists in savefig_kwargs.
631+ # FIXME: Using 'bbox_inches' doesn't currently work with
632+ # writers that pipe the data to the command because this
633+ # requires a fixed frame size (see Ryan May's reply in this
634+ # thread: [1]). Thus we drop the 'bbox_inches' argument if it
635+ # exists in savefig_kwargs.
629636 #
630- # [1] http://matplotlib.1069221.n5.nabble.com/Animation-class-let-save-accept-kwargs-which-are-passed-on-to-savefig-td39627.html
637+ # [1] (http://matplotlib.1069221.n5.nabble.com/
638+ # Animation-class-let-save-accept-kwargs-which-
639+ # are-passed-on-to-savefig-td39627.html)
631640 #
632- if savefig_kwargs . has_key ( 'bbox_inches' ) :
641+ if 'bbox_inches' in savefig_kwargs :
633642 if not (writer in ['ffmpeg_file' , 'mencoder_file' ] or
634- isinstance (writer , (FFMpegFileWriter , MencoderFileWriter ))):
635- print ("Warning: discarding the 'bbox_inches' argument in " \
636- "'savefig_kwargs' as it is only currently supported " \
637- "with the writers 'ffmpeg_file' and 'mencoder_file' " \
638- "(writer used: '{}')." .format (writer if isinstance (writer , str )
639- else writer .__class__ .__name__ ))
643+ isinstance (writer ,
644+ (FFMpegFileWriter , MencoderFileWriter ))):
645+ print ("Warning: discarding the 'bbox_inches' argument in "
646+ "'savefig_kwargs' as it is only currently supported "
647+ "with the writers 'ffmpeg_file' and 'mencoder_file' "
648+ "(writer used: "
649+ "'{}')." .format (writer if isinstance (writer , str )
650+ else writer .__class__ .__name__ ))
640651 savefig_kwargs .pop ('bbox_inches' )
641652
642653 # Need to disconnect the first draw callback, since we'll be doing
@@ -677,7 +688,8 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
677688 if is_string_like (writer ):
678689 if writer in writers .avail :
679690 writer = writers [writer ](fps , codec , bitrate ,
680- extra_args = extra_args , metadata = metadata )
691+ extra_args = extra_args ,
692+ metadata = metadata )
681693 else :
682694 import warnings
683695 warnings .warn ("MovieWriter %s unavailable" % writer )
@@ -708,7 +720,7 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
708720 # Reconnect signal for first draw if necessary
709721 if reconnect_first_draw :
710722 self ._first_draw_id = self ._fig .canvas .mpl_connect ('draw_event' ,
711- self ._start )
723+ self ._start )
712724
713725 def _step (self , * args ):
714726 '''
@@ -756,7 +768,7 @@ def _pre_draw(self, framedata, blit):
756768 def _draw_frame (self , framedata ):
757769 # Performs actual drawing of the frame.
758770 raise NotImplementedError ('Needs to be implemented by subclasses to'
759- ' actually make an animation.' )
771+ ' actually make an animation.' )
760772
761773 def _post_draw (self , framedata , blit ):
762774 # After the frame is rendered, this handles the actual flushing of
@@ -799,7 +811,7 @@ def _setup_blit(self):
799811 self ._blit_cache = dict ()
800812 self ._drawn_artists = []
801813 self ._resize_id = self ._fig .canvas .mpl_connect ('resize_event' ,
802- self ._handle_resize )
814+ self ._handle_resize )
803815 self ._post_draw (None , self ._blit )
804816
805817 def _handle_resize (self , * args ):
@@ -821,7 +833,7 @@ def _end_redraw(self, evt):
821833 self .event_source .start ()
822834 self ._fig .canvas .mpl_disconnect (self ._resize_id )
823835 self ._resize_id = self ._fig .canvas .mpl_connect ('resize_event' ,
824- self ._handle_resize )
836+ self ._handle_resize )
825837
826838
827839class TimedAnimation (Animation ):
@@ -836,7 +848,7 @@ class TimedAnimation(Animation):
836848 the animation.
837849 '''
838850 def __init__ (self , fig , interval = 200 , repeat_delay = None , repeat = True ,
839- event_source = None , * args , ** kwargs ):
851+ event_source = None , * args , ** kwargs ):
840852 # Store the timing information
841853 self ._interval = interval
842854 self ._repeat_delay = repeat_delay
@@ -952,13 +964,13 @@ class FuncAnimation(TimedAnimation):
952964
953965 *init_func* is a function used to draw a clear frame. If not given, the
954966 results of drawing from the first item in the frames sequence will be
955- used. This function will be called once before the first frame.
967+ used. This function will be called once before the first frame.
956968
957969 If blit=True, *func* and *init_func* should return an iterable of
958970 drawables to clear.
959971 '''
960972 def __init__ (self , fig , func , frames = None , init_func = None , fargs = None ,
961- save_count = None , ** kwargs ):
973+ save_count = None , ** kwargs ):
962974 if fargs :
963975 self ._args = fargs
964976 else :
0 commit comments