matplotlib动画线条图保持空白
我试图遵循此处的基本动画教程,并对其进行调整以显示已经计算出的数据集,而不是每帧都对函数进行评估,但是却陷入了困境。我的数据集包含列表中包含的随时间的XY坐标,satxpos
并且satypos
我试图创建一个动画,使其跟踪从数据集的开头到结尾的一条线,每0.1秒显示1个新点。对我要去哪里有帮助吗?
from matplotlib import pyplot as plt
from matplotlib import animation
import numpy as np
Code here creates satxpos and satypos as lists
fig = plt.figure()
ax = plt.axes(xlim=(-1e7,1e7), ylim = (-1e7,1e7))
line, = ax.plot([], [], lw=2)
def init():
line.set_data([], [])
return line,
def animate(i):
line.set_data(satxpos[i], satypos[i])
return line,
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames = len(satxpos), interval = 1, blit=True)
编辑:该代码运行时没有错误,但是生成了一个空白的绘图窗口,其中没有显示点/线并且没有动画。数据集已正确生成,并且在静态图中的视图良好。