Skip to content

Commit 0dcd06f

Browse files
authored
Merge pull request matplotlib#30206 from anntzer/ad
Use collections.deque to store animation cache data.
2 parents 6e51bec + e77c17f commit 0dcd06f

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

lib/matplotlib/animation.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import abc
22
import base64
3+
import collections
34
import contextlib
45
from io import BytesIO, TextIOWrapper
56
import itertools
@@ -1708,13 +1709,13 @@ def iter_frames(frames=frames):
17081709
self._cache_frame_data = cache_frame_data
17091710

17101711
# Needs to be initialized so the draw functions work without checking
1711-
self._save_seq = []
1712+
self._save_seq = collections.deque([], self._save_count)
17121713

17131714
super().__init__(fig, **kwargs)
17141715

17151716
# Need to reset the saved seq, since right now it will contain data
17161717
# for a single frame from init, which is not what we want.
1717-
self._save_seq = []
1718+
self._save_seq.clear()
17181719

17191720
def new_frame_seq(self):
17201721
# Use the generating function to generate a new frame sequence
@@ -1727,8 +1728,7 @@ def new_saved_frame_seq(self):
17271728
if self._save_seq:
17281729
# While iterating we are going to update _save_seq
17291730
# so make a copy to safely iterate over
1730-
self._old_saved_seq = list(self._save_seq)
1731-
return iter(self._old_saved_seq)
1731+
return iter([*self._save_seq])
17321732
else:
17331733
if self._save_count is None:
17341734
frame_seq = self.new_frame_seq()
@@ -1773,13 +1773,12 @@ def _init_draw(self):
17731773
'return a sequence of Artist objects.')
17741774
for a in self._drawn_artists:
17751775
a.set_animated(self._blit)
1776-
self._save_seq = []
1776+
self._save_seq.clear()
17771777

17781778
def _draw_frame(self, framedata):
17791779
if self._cache_frame_data:
17801780
# Save the data for potential saving of movies.
17811781
self._save_seq.append(framedata)
1782-
self._save_seq = self._save_seq[-self._save_count:]
17831782

17841783
# Call the func with framedata and args. If blitting is desired,
17851784
# func needs to return a sequence of any artists that were modified.

0 commit comments

Comments
 (0)