My jupyter interactive window in vscode cannot plot a gif correctly #16343
Unanswered
adier-dev
asked this question in
Questions and Answers
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I use following codes trying to create a gif in vscode using jupyter extensions, but I only get a static picture, not a gif. But I put the same codes in jupyter itself (not vscode extensions), it works. I don't know what I should do to fix the problem.
My python version is 3.9.20.
`
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.animation import PillowWriter
from IPython.display import Image
创建数据
x = np.linspace(0, 2 * np.pi, 100)
初始化图形
fig, ax = plt.subplots()
line, = ax.plot(x, np.sin(x))
更新函数
def update(frame):
line.set_ydata(np.sin(x + frame / 10.0)) # 更新 y 数据
return line,
创建动画
ani = animation.FuncAnimation(fig, update, frames=100, blit=True)
保存动画为 GIF
writer = PillowWriter(fps=20)
ani.save("sine_wave.gif", writer=writer)
显示动画
plt.show()
`
Beta Was this translation helpful? Give feedback.
All reactions