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

Commite77c17f

Browse files
committed
Use collections.deque to store animation cache data.
deques are exactly suited for the task at hand, and should be (here,marginally) more efficient than repeatedly slicing off the start of thelist.Also drop unneeded reference to old_frame_seq (the iterator alreadykeeps that data alive).
1 parentbebb263 commite77c17f

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
importabc
22
importbase64
3+
importcollections
34
importcontextlib
45
fromioimportBytesIO,TextIOWrapper
56
importitertools
@@ -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
defnew_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
ifself._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-
returniter(self._old_saved_seq)
1731+
returniter([*self._save_seq])
17321732
else:
17331733
ifself._save_countisNone:
17341734
frame_seq=self.new_frame_seq()
@@ -1773,13 +1773,12 @@ def _init_draw(self):
17731773
'return a sequence of Artist objects.')
17741774
forainself._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
ifself._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)

[8]ページ先頭

©2009-2025 Movatter.jp