我的代码:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
def animate(i):
ax.set_data(ax.scatter(ptx1, pty1, ptz1, c='red'),
ax.scatter(ptx2, pty2, ptz2, c='blue'),
ax.scatter(ptx3, pty3, ptz3, c='green'))
ani = FuncAnimation(fig, animate, frames=10, interval=200)
plt.show()我在试着画出三个点的运动。每个ptx/y/z/1/2/3都是给出点坐标的浮点数列表。我只是不确定如何使用FuncAnimation来动画我的点。任何帮助都将不胜感激!
发布于 2016-11-20 23:58:23
简单的例子。animate被调用了很多次,每次你必须使用不同的数据来观看动画。
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import random
# create some random data
ptx1 = [random.randint(0,100) for x in range(20)]
pty1 = [random.randint(0,100) for x in range(20)]
fig = plt.figure()
ax = fig.add_subplot(111)
def animate(i):
# use i-th elements from data
ax.scatter(ptx1[:i], pty1[:i], c='red')
# or add only one element from list
#ax.scatter(ptx1[i], pty1[i], c='red')
ani = FuncAnimation(fig, animate, frames=20, interval=500)
plt.show()https://stackoverflow.com/questions/40705496
复制相似问题