Вы можете создать подкласс ArtistAnimation
и переписать метод _step, например:
class SnapShotAnimation(ArtistAnimation):
def __init__(self, fig, artists, snapshot_delay, *args, **kwargs):
self._snapshot_delay = snapshot_delay
self._time_to_snapshot = snapshot_delay
ArtistAnimation.__init__(self, fig, artists, *args, **kwargs)
def _step(self, *args):
if self._time_to_snapshot <= 0:
do_snapshot()
self._time_to_snapshot = self._snap_shot_delay #reset timer
else:
self._time_to_snapshot -= self._interval
ArtistAnimation._step(*args) #ancestor method maybe better at start
def do_snapshot(self):
"""Your actual snapshot code comes here - basically saving to a output"""
fname = 'snapshot.png'
self._fig.savefig(fname)
добавив:
snapshot_delay = 1000 # time in ms
, изменив:
ani=SnapShotAnimation(fig,result,snapshot_delay, interval=10,repeat=False)
вваш пример источника.
Для лучшего понимания, что и как делать, я бы рекомендовал взглянуть на matplotlib sources .