Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf04cf57

Browse files
authored
Merge pull request#19045 from anntzer/afs
Inline MovieWriter._frame_sink.
2 parentsa86eee3 +e3cc885 commitf04cf57

File tree

1 file changed

+10
-27
lines changed

1 file changed

+10
-27
lines changed

‎lib/matplotlib/animation.py

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -349,21 +349,16 @@ def grab_frame(self, **savefig_kwargs):
349349
# All frames must have the same size to save the movie correctly.
350350
self.fig.set_size_inches(self._w,self._h)
351351
# Save the figure data to the sink, using the frame format and dpi.
352-
self.fig.savefig(self._frame_sink(),format=self.frame_format,
352+
self.fig.savefig(self._proc.stdin,format=self.frame_format,
353353
dpi=self.dpi,**savefig_kwargs)
354354

355-
def_frame_sink(self):
356-
"""Return the place to which frames should be written."""
357-
returnself._proc.stdin
358-
359355
def_args(self):
360356
"""Assemble list of encoder-specific command-line arguments."""
361357
returnNotImplementedError("args needs to be implemented by subclass.")
362358

363359
def_cleanup(self):# Inline to finish() once cleanup() is removed.
364360
"""Clean-up and collect the process used to write the movie file."""
365361
out,err=self._proc.communicate()
366-
self._frame_sink().close()
367362
# Use the encoding/errors that universal_newlines would use.
368363
out=TextIOWrapper(BytesIO(out)).read()
369364
err=TextIOWrapper(BytesIO(err)).read()
@@ -483,30 +478,18 @@ def _base_temp_name(self):
483478
# for extension and the prefix.
484479
returnself.fname_format_str% (self.temp_prefix,self.frame_format)
485480

486-
def_frame_sink(self):
487-
# Creates a filename for saving using the basename and the current
488-
# counter.
489-
path=Path(self._base_temp_name()%self._frame_counter)
490-
491-
# Save the filename so we can delete it later if necessary
492-
self._temp_paths.append(path)
493-
_log.debug('FileMovieWriter.frame_sink: saving frame %d to path=%s',
494-
self._frame_counter,path)
495-
self._frame_counter+=1# Ensures each created name is 'unique'
496-
497-
# This file returned here will be closed once it's used by savefig()
498-
# because it will no longer be referenced and will be gc-ed.
499-
returnopen(path,'wb')
500-
501481
defgrab_frame(self,**savefig_kwargs):
502482
# docstring inherited
503483
# Overloaded to explicitly close temp file.
504-
_log.debug('MovieWriter.grab_frame: Grabbing frame.')
505-
# Tell the figure to save its data to the sink, using the
506-
# frame format and dpi.
507-
withself._frame_sink()asmyframesink:
508-
self.fig.savefig(myframesink,format=self.frame_format,
509-
dpi=self.dpi,**savefig_kwargs)
484+
# Creates a filename for saving using basename and counter.
485+
path=Path(self._base_temp_name()%self._frame_counter)
486+
self._temp_paths.append(path)# Record the filename for later cleanup.
487+
self._frame_counter+=1# Ensures each created name is unique.
488+
_log.debug('FileMovieWriter.grab_frame: Grabbing frame %d to path=%s',
489+
self._frame_counter,path)
490+
withopen(path,'wb')assink:# Save figure to the sink.
491+
self.fig.savefig(sink,format=self.frame_format,dpi=self.dpi,
492+
**savefig_kwargs)
510493

511494
deffinish(self):
512495
# Call run here now that all frame grabbing is done. All temp files

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp