Created
January 6, 2022 16:14
-
-
Save eigenvivek/5a4404b8011d4735026a382a5f61c159 to your computer and use it in GitHub Desktop.
Matplotlib animations in VSCode jupyter notebook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# %% | |
%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