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

Appearance settings

Commit 5ee8428

Browse filesBrowse files
committed
Defaut to writing animation frames to a temporary directory.
(We could later deprecate clean_temp, as the user can simply pass a non-None frame_prefix to write temporary frames whereever they want and keep them there.)
1 parent 745dcae commit 5ee8428
Copy full SHA for 5ee8428

File tree

Expand file treeCollapse file tree

2 files changed

+25
-12
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+25
-12
lines changed

‎doc/api/prev_api_changes/api_changes_3.2.0/behavior.rst

Copy file name to clipboardExpand all lines: doc/api/prev_api_changes/api_changes_3.2.0/behavior.rst
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,9 @@ package, and Axes methods that take a ``norm`` parameter.
299299

300300
If extra kwargs are passed to `.LogScale`, `TypeError` will now be
301301
raised instead of `ValueError`.
302+
303+
`FileMovieWriter` temporary frames directory
304+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
305+
`.FileMovieWriter` now defaults to writing temporary frames in a temporary
306+
directory, which is always cleared at exit. In order to keep the individual
307+
frames saved on the filesystem, pass an explicit *frame_prefix*.

‎lib/matplotlib/animation.py

Copy file name to clipboardExpand all lines: lib/matplotlib/animation.py
+19-12Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def __init__(self, *args, **kwargs):
431431
MovieWriter.__init__(self, *args, **kwargs)
432432
self.frame_format = mpl.rcParams['animation.frame_format']
433433

434-
def setup(self, fig, outfile, dpi=None, frame_prefix='_tmp',
434+
def setup(self, fig, outfile, dpi=None, frame_prefix=None,
435435
clear_temp=True):
436436
'''Perform setup for writing the movie file.
437437
@@ -446,13 +446,13 @@ def setup(self, fig, outfile, dpi=None, frame_prefix='_tmp',
446446
controls the size in pixels of the resulting movie file.
447447
Default is fig.dpi.
448448
frame_prefix : str, optional
449-
The filename prefix to use for temporary files. Defaults to
450-
``'_tmp'``.
449+
The filename prefix to use for temporary files. If None (the
450+
default), files are written to a temporary directory which is
451+
deleted by `cleanup` (regardless of the value of *clear_temp*).
451452
clear_temp : bool, optional
452453
If the temporary files should be deleted after stitching
453454
the final result. Setting this to ``False`` can be useful for
454455
debugging. Defaults to ``True``.
455-
456456
'''
457457
self.fig = fig
458458
self.outfile = outfile
@@ -461,8 +461,13 @@ def setup(self, fig, outfile, dpi=None, frame_prefix='_tmp',
461461
self.dpi = dpi
462462
self._adjust_frame_size()
463463

464+
if frame_prefix is None:
465+
self._tmpdir = TemporaryDirectory()
466+
self.temp_prefix = str(Path(self._tmpdir.name, 'tmp'))
467+
else:
468+
self._tmpdir = None
469+
self.temp_prefix = frame_prefix
464470
self.clear_temp = clear_temp
465-
self.temp_prefix = frame_prefix
466471
self._frame_counter = 0 # used for generating sequential file names
467472
self._temp_paths = list()
468473
self.fname_format_str = '%s%%07d.%s'
@@ -524,13 +529,15 @@ def finish(self):
524529

525530
def cleanup(self):
526531
MovieWriter.cleanup(self)
527-
528-
# Delete temporary files
529-
if self.clear_temp:
530-
_log.debug('MovieWriter: clearing temporary paths=%s',
531-
self._temp_paths)
532-
for path in self._temp_paths:
533-
path.unlink()
532+
if self._tmpdir:
533+
_log.debug('MovieWriter: clearing temporary path=%s', self._tmpdir)
534+
self._tmpdir.cleanup()
535+
else:
536+
if self.clear_temp:
537+
_log.debug('MovieWriter: clearing temporary paths=%s',
538+
self._temp_paths)
539+
for path in self._temp_paths:
540+
path.unlink()
534541

535542

536543
@writers.register('pillow')

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.