Python 带有时间戳的Matplotlib散点图动画

Python 带有时间戳的Matplotlib散点图动画,python,animation,matplotlib,time-series,scatter-plot,Python,Animation,Matplotlib,Time Series,Scatter Plot,您好,提前感谢您提供的任何提示和建议。我正在尝试创建一个动画散点图,根据我在python中读取的模型结果更改点颜色。如果我可以在动画中显示更新的时间戳,那么模型结果将更容易解释 我试着把这个问题的答案加入到这篇文章中: ,但我认为我使用的是分散数据集而不是行,这会使数据返回的方式变得复杂,我不确定如何纠正这个问题 这段代码交替地闪烁时间步长和散射动画,这会造成分心和无用的视觉效果 # load result testModel.addResult(testDye,type='dye') xs

您好,提前感谢您提供的任何提示和建议。我正在尝试创建一个动画散点图,根据我在python中读取的模型结果更改点颜色。如果我可以在动画中显示更新的时间戳,那么模型结果将更容易解释

我试着把这个问题的答案加入到这篇文章中: ,但我认为我使用的是分散数据集而不是行,这会使数据返回的方式变得复杂,我不确定如何纠正这个问题

这段代码交替地闪烁时间步长和散射动画,这会造成分心和无用的视觉效果

 # load result
testModel.addResult(testDye,type='dye')
xs = testModel.grid['x']
ys = testModel.grid['y']
zs = testModel.grid['z']

# graphing
fig = plt.figure()
ax = fig.add_subplot(111)
gcf = plt.gcf()
scat = ax.scatter(xs,ys)
timetext = gcf.text(0.2, 0.2, '', size = 14)

def animate(i):
    print i
    actDye = testModel.getResult(type='dye',layer=1,tIndex=i)
    scat.set_array((actDye/1000)*100) #update colors of points 
    timetext.set_text(i)
    return scat,

def init():
    actDye = testModel.getResult(type='dye',layer=1,tIndex=0)
    scat.set_array((actDye/1000)*100) #update colors of points
    return scat,

ani = animation.FuncAnimation(fig,animate,np.arange(0,200),init_func=init, interval=500, blit=True)

plt.show()
我认为将timetext与scat一起返回可以解决这个问题(就像在另一张海报上一样),但我无法正确使用语法。切换到这段代码会给我一个错误,即“PathCollection”对象不可编辑

def animate(i):
    print i
    actDye = testModel.getResult(type='dye',layer=1,tIndex=i)
    scat.set_array((actDye/1000)*100) #update colors of points 
    timetext.set_text(i)
    return tuple(scat,) + (timetext,)
我应该做些什么不同的事情?谢谢