October 2018
Beginner to intermediate
676 pages
18h 30m
English
You can run all the steps of the previous recipe at once, as shown here, to create the animation:
fig, ax = plt.subplots()x = np.arange(-10, 10, 0.01)y = 1 / (1 + np.exp(-x))line, = ax.plot(x, y)def init(): # only required for blitting to give a clean slate. line.set_ydata([np.nan] * len(x)) return linedef animate(i): line.set_ydata(1 / (1 + np.exp(-(x+i/100)))) # update the data. return lineani = FuncAnimation(fig, animate, 1000, init_func=init, blit=True, interval=2, save_count=50, repeat=False, repeat_delay=1000)
There are two ways you can save the figure:
ani.save("sigmoid.mp4")
You can also save it like this:
from matplotlib.animation import FFMpegWriterwriter = FFMpegWriter(fps=25, metadata=dict(title='expdecay',artist='line'), ...
Read now
Unlock full access