CHAPTER 07 · 作品已接入
animation 动画
用 FuncAnimation 逐帧更新图形。
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()