Skip to content

Instantly share code, notes, and snippets.

@thomasniebler
Created May 6, 2019 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasniebler/eca5d958572f557f4c3c00462405142e to your computer and use it in GitHub Desktop.
Save thomasniebler/eca5d958572f557f4c3c00462405142e to your computer and use it in GitHub Desktop.
animation plot in jupyter with several actors
fig, ax = plt.subplots()
ax.set_xlim(( 0, 2))
ax.set_ylim((-2, 2))
line1, = ax.plot([], [], lw=2)
line2, = ax.plot([], [], lw=2)
line3, = ax.plot([], [], lw=2)
# initialization function: plot the background of each frame
def init():
line1.set_data([], [])
line2.set_data([], [])
line3.set_data([], [])
return (line1, line2, line3, )
# animation function. This is called sequentially
def animate(i):
x = np.linspace(0, 2, 1000)
y = np.sin(2 * np.pi * (x - 0.01 * i))
line1.set_data(x, y)
line2.set_data(x * 2, y)
line3.set_data(x * 3, y)
return (line1, line2, line3, )
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=100, interval=100, blit=True)
HTML(anim.to_html5_video())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment