Skip to content

Commit

Permalink
Merge pull request #2634 from tacaswell/animation_iter_length
Browse files Browse the repository at this point in the history
address FuncAnimantion trying to take lengths of generators
  • Loading branch information
pelson committed Jan 6, 2014
2 parents a3abbb4 + 1b144e8 commit 397c27a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/matplotlib/animation.py
Expand Up @@ -1000,7 +1000,8 @@ def __init__(self, fig, func, frames=None, init_func=None, fargs=None,
self._iter_gen = frames
elif iterable(frames):
self._iter_gen = lambda: iter(frames)
self.save_count = len(frames)
if hasattr(frames, '__len__'):
self.save_count = len(frames)
else:
self._iter_gen = lambda: xrange(frames).__iter__()
self.save_count = frames
Expand Down
19 changes: 19 additions & 0 deletions lib/matplotlib/tests/test_animation.py
Expand Up @@ -58,6 +58,25 @@ def animate(i):
"see issues #1891 and #2679")


@cleanup
def test_no_length_frames():
fig, ax = plt.subplots()
line, = ax.plot([], [])

def init():
line.set_data([], [])
return line,

def animate(i):
x = np.linspace(0, 10, 100)
y = np.sin(x + i)
line.set_data(x, y)
return line,

anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=iter(range(5)))


if __name__ == "__main__":
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 comments on commit 397c27a

Please sign in to comment.