【发布时间】:2021-02-13 05:31:48
【问题描述】:
使用 Jupyter Notebook,我可以创建动画情节(基于this sample code):
%matplotlib notebook
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig, ax = plt.subplots()
x = np.arange(0, 2*np.pi, 0.01)
line, = ax.plot(x, np.sin(x))
def init():
line.set_ydata([np.nan] * len(x))
return line,
def animate(i):
line.set_ydata(np.sin(x + i / 100)) # update the data.
return line,
ani = animation.FuncAnimation(
fig, animate, init_func=init, interval=2, blit=True, save_count=50)
plt.show()
是否可以在 Visual Studio Code 的笔记本编辑器中执行此操作?我认为它涉及到魔术%matplotlib notebook模式,VS Code似乎不支持,但我不知道是否有替代方案。
【问题讨论】:
-
This blog post 讨论了如何将动画渲染为嵌入的 HTML5 绘图,但这不是我的目标:我的绘图将根据实时数据馈送进行更新。
标签: python matplotlib visual-studio-code jupyter-notebook