8000 FuncAnimation w/o init_func breaks when saving · Issue #5399 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
FuncAnimation w/o init_func breaks when saving #5399
Closed
@cbreeden

Description

@cbreeden

I was trying to work out a patch to #5335 and ran into issues introduced in merge #4800. The following code is slightly simplified example from the animations examples:

%matplotlib nbagg

import matplotlib
import matplotlib.pyplot as plt
import matplotlib.animation as animation

import numpy as np

def update_line(num, data, line):
    line.set_data(data[...,:num])
    return line,

fig = plt.figure()

plt.xlim(0, 1)
plt.ylim(0, 1)

data = np.random.rand(2, 10)
l, = plt.plot([], [], 'r-')

ani = animation.FuncAnimation(fig, update_line, 10, fargs=(data, l),
                                                   interval=50, blit=True)
ani.save('im.gif', writer='imagemagick')

running this yields:

im 1

The animation displays correctly in the notebook. The issue is introduced here

for anim in all_anim:
. When FuncAnimation._init_draw() is called, if no init_func is given, the first frame sequence is appended to self._save_seq. After which,
for data in zip(*[a.new_saved_frame_seq()
is executed and FuncAnimation.new_saved_seq() then only returns the first drawn frame for which to iterate over. The end result is an animation file with only one frame.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0