我有一些数据,该数据由2d中的点云的时间序列组成(执行PCA之后)。我想拍一部电影来显示点云随时间的演变,并且我编写了以下代码:
import matplotlib.pyplot as plt
import matplotlib.animation
fig, ax = plt.subplots()
times = np.linspace(-1496, 1500, 750)
def init():
i = 0
xs = X_PCA[:,0,i]
ys = X_PCA[:,1,i]
scat = ax.scatter(xs, ys, c=y)
ax.set_title('%d ms' % times[timepoint])
ax.set_xlabel('PC1 (%.1f%%)' % (100 * variance_explained[0,i]))
ax.set_ylabel('PC2 (%.1f%%)' % (100 * variance_explained[1,i]))
ax.set_xlim(0, 60)
ax.set_ylim(0, 60)
return scat,
def animate(i):
xs = X_PCA[:,0,i]
ys = X_PCA[:,1,i]
scat = ax.scatter(xs, ys, c=y)
ax.set_title('%d ms' % times[i])
ax.set_xlabel('PC1 (%.1f%%)' % (100 * variance_explained[0,i]))
ax.set_ylabel('PC2 (%.1f%%)' % (100 * variance_explained[1,i]))
return scat,
ani = matplotlib.animation.FuncAnimation(fig, animate, range(750), init_func=init, interval=5, blit=True)
plt.show()
我的问题是,这些框架是相互重叠绘制的,而不是刷新框架。我感到可以通过在某个地方调用scat.remove()
来解决此问题,但是我尝试了几种组合,但都没有给出期望的结果。
谢谢,
菲利普