【发布时间】:2014-12-11 16:56:47
【问题描述】:
我得到了一个 .dat 文件,其中包含 3d 空间中段的坐标。 该文件有几行,每一行代表特定时间的位置。
我试过这段代码:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from mpl_toolkits.mplot3d import Axes3D
dati = np.loadtxt('dati.dat')
t=0
p1=[dati[t,1],dati[t,2],dati[t,3]]
p2=[dati[t,4],dati[t,5],dati[t,6]]
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
seg,=ax.plot(p1,p2)
def updateFigure(t,dati,seg):
p1=[dati[t,1],dati[t,2],dati[t,3]]
p2=[dati[t,4],dati[t,5],dati[t,6]]
seg.set_data(p1,p2)
return seg,
ani=animation.FuncAnimation(fig, updateFigure,iMax, fargs=(dati,seg), interval=100, blit=True)
plt.show()
程序不报错但人形不动。 相同的代码,稍作修改,在 2d 空间中有效..
【问题讨论】:
-
您应该提供您的数据文件 (
dati.dat)。否则人们无法运行您的代码。
标签: python animation matplotlib