Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fixes to funcanimation #4800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 31, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions examples/animation/animate_decay.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ def data_gen(t=0):
t += 0.1
yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)


def init():
ax.set_ylim(-1.1, 1.1)
ax.set_xlim(0, 10)
del xdata[:]
del ydata[:]
line.set_data(xdata, ydata)
return line,

fig, ax = plt.subplots()
line, = ax.plot([], [], lw=2)
ax.set_ylim(-1.1, 1.1)
ax.set_xlim(0, 5)
ax.grid()
xdata, ydata = [], []

Expand All @@ -33,5 +40,5 @@ def run(data):
return line,

ani = animation.FuncAnimation(fig, run, data_gen, blit=False, interval=10,
repeat=False)
repeat=False, init_func=init)
plt.show()
9 changes: 8 additions & 1 deletion lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ def _start(self, *args):
# actually start the event_source. We also disconnect _start
# from the draw_events
self.event_source.add_callback(self._step)
self._init_draw()
self.event_source.start()
self._fig.canvas.mpl_disconnect(self._first_draw_id)
self._first_draw_id = None # So we can check on save
Expand Down Expand Up @@ -760,6 +761,9 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
# since GUI widgets are gone. Either need to remove extra code to
# allow for this non-existant use case or find a way to make it work.
with writer.saving(self._fig, filename, dpi):
for anim in all_anim:
# Clear the initial frame
anim._init_draw()
for data in zip(*[a.new_saved_frame_seq()
for a in all_anim]):
for anim, d in zip(all_anim, data):
Expand Down Expand Up @@ -1080,7 +1084,10 @@ def new_saved_frame_seq(self):
# no saved frames, generate a new frame sequence and take the first
# save_count entries in it.
if self._save_seq:
return iter(self._save_seq)
# While iterating we are going to update _save_seq
# so make a copy to safely iterate over
self._old_saved_seq = self._save_seq.copy()
return iter(self._old_saved_seq)
else:
return itertools.islice(self.new_frame_seq(), self.save_count)

Expand Down