← 返回章节索引

CHAPTER 07 · 作品已接入

animation 动画

用 FuncAnimation 逐帧更新图形。

10075502500246810FuncAnimation · Framesframe 4 / 4
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

fig, ax = plt.subplots()
line, = ax.plot(x, y)
def update(frame):
line.set_ydata(np.sin(x + frame / 10))
return line,
anim = FuncAnimation(fig, update, frames=60)
plt.show()
mpl3d 工具包3D 图表animation 动画