matplotlib三維繪制動(dòng)態(tài)曲線
api里面的例子比較復(fù)雜,本人自己寫了一個(gè)例子繪制一條三維動(dòng)態(tài)曲線
1 #外部獲得數(shù)據(jù) 2 myCurve = np.fromfile('data.bin', dtype=np.float).reshape(-1,3) 3 xLength,j = myCurve.shape 4 fig = plt.figure() 5 ax1=plt.axes(projection='3d') 6 #初始化繪制 7 line, = ax1.plot([],[],[],animated=True) 8 #定義動(dòng)畫函數(shù) 9 def animate(i): 10 line.set_xdata(myCurve[:i+1,0]) 11 line.set_ydata(myCurve[:i+1,1]) 12 line.set_3d_properties(myCurve[:i+1,3]) 13 # 這個(gè),很關(guān)鍵,不然無法迭代 14 return line, 15 ani = animation.FuncAnimation(fig,animate,xLength,interal=5, repeat=False, bit=True) 16 plt.show()

浙公網(wǎng)安備 33010602011771號(hào)