Skip to content

Instantly share code, notes, and snippets.

@eigenvivek
Created January 6, 2022 16:14
Show Gist options
  • Save eigenvivek/5a4404b8011d4735026a382a5f61c159 to your computer and use it in GitHub Desktop.
Save eigenvivek/5a4404b8011d4735026a382a5f61c159 to your computer and use it in GitHub Desktop.
Matplotlib animations in VSCode jupyter notebook
# %%
%matplotlib ipympl
# %%
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation
# %%
fig, ax = plt.subplots()
line, = ax.plot([])
ax.set_xlim(0, 2*np.pi)
ax.set_ylim(-1.1, 1.1)
def animate(frame):
x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x + 2*np.pi * frame / 100)
line.set_data((x, y))
return line
anim = FuncAnimation(fig, animate, frames=100, interval=20)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment