I use matplotlib animation, calling:
plot = animation.FuncAnimation(fig, update, frames=data_gen(a), init_func=init, interval=10, blit=True)
Here "a" is the initial value for the data_gen function, which looks like this:
data_gen(x)
old_x = x
while True:
new_x = func(old_x)
old_x = new_x
yield new_x
The purpose of this code is for data_gen to create a new value for new_x every time the animated plot is updated.
BUT ... this happens instead:
animation.py raises an error in the init () method of the FuncAnimation class.
The problem occurs in this code:
elif iterable(frames):
self._iter_gen = lambda: iter(frames)
self.save_count = len(frames)
Error: "TypeError: object of type" generator "does not have len ()"
It looks like data_gen iserable, but it does not have len ().
Here is the init () code in the FuncAnimation class:
if frames is None:
self._iter_gen = itertools.count
elif isinstance(frames, collections.Callable):
self._iter_gen = frames
elif iterable(frames):
self._iter_gen = lambda: iter(frames)
self.save_count = len(frames)
else:
self._iter_gen = lambda: iter(list(range(frames)))
self.save_count = frames
, data_gen .Callable. , len (frames) .
, , !