我寫了一個簡單的腳本,基於代碼herematplotlib - 更快的幀速率?
我只需要顯示點,不需要線。
下面的腳本正確顯示的點,但我想看到的點在假設30fps的幀速率移動更快,在可配置的方式。
import matplotlib
matplotlib.use('TKAgg')
import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.colors import cnames
from matplotlib import animation
NbOfObjects = 3
fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1], projection='3d')
ax.axis('on')
ax.set_xlim((-1.5, 1.5))
ax.set_ylim((-1.5, 1.5))
ax.set_zlim((0, 1.5))
ax.set_xlabel('x axis')
ax.set_ylabel('y axis')
ax.set_zlabel('z axis')
# set point-of-view: specified by (altitude degrees, azimuth degrees)
ax.view_init(30, 30)
# choose a different color for each trajectory
colors = plt.cm.jet(np.linspace(0, 1, NbOfObjects))
# set up points
pts = sum([ax.plot([], [], [], 'o', c=c)
for c in colors], [])
data = [[[0.0, 0.0, 0.0], [-1.0, -1.0, 1.0], [1.0, 1.0, 1.0]],
[[0.0, 0.0, 0.0], [-1.0, -1.0, 1.0], [1.0, 1.0, 1.0]],
[[0.0, 0.0, 0.0], [-1.0, -1.0, 1.0], [1.0, 1.0, 1.0]],
[[0.0, 0.0, 0.0], [-1.0, -1.0, 1.0], [1.0, 1.0, 1.0]],
[[0.0, 0.0, 0.0], [-1.0, -1.0, 1.0], [1.0, 1.0, 1.0]],
[[0.0, 0.0, 0.0], [-1.0, -1.0, 1.0], [1.0, 1.0, 1.0]],
[[0.0, 0.0, 0.0], [-1.0, -1.0, 1.0], [1.0, 1.0, 1.0]],
[[0.0, 0.0, 0.0], [-1.0, -1.0, 1.0], [1.0, 1.0, 1.0]],
[[0.0, 0.0, 0.0], [-1.0, -1.0, 1.0], [1.0, 1.0, 1.0]],
[[0.0, 0.0, 0.0], [-1.0, -1.0, 1.0], [1.0, 1.0, 1.0]],
[[1.0, 0.0, 0.0], [0.0, -1.0, 1.0], [-1.0, 1.0, 1.0]],
[[1.0, 0.0, 0.0], [0.0, -1.0, 1.0], [-1.0, 1.0, 1.0]],
[[1.0, 0.0, 0.0], [0.0, -1.0, 1.0], [-1.0, 1.0, 1.0]],
[[1.0, 0.0, 0.0], [0.0, -1.0, 1.0], [-1.0, 1.0, 1.0]],
[[1.0, 0.0, 0.0], [0.0, -1.0, 1.0], [-1.0, 1.0, 1.0]],
[[1.0, 0.0, 0.0], [0.0, -1.0, 1.0], [-1.0, 1.0, 1.0]],
[[1.0, 0.0, 0.0], [0.0, -1.0, 1.0], [-1.0, 1.0, 1.0]],
[[1.0, 0.0, 0.0], [0.0, -1.0, 1.0], [-1.0, 1.0, 1.0]],
[[1.0, 0.0, 0.0], [0.0, -1.0, 1.0], [-1.0, 1.0, 1.0]],
[[1.0, 0.0, 0.0], [0.0, -1.0, 1.0], [-1.0, 1.0, 1.0]],
[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0], [-1.0, -1.0, 1.0]],
[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0], [-1.0, -1.0, 1.0]],
[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0], [-1.0, -1.0, 1.0]],
[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0], [-1.0, -1.0, 1.0]],
[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0], [-1.0, -1.0, 1.0]],
[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0], [-1.0, -1.0, 1.0]],
[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0], [-1.0, -1.0, 1.0]],
[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0], [-1.0, -1.0, 1.0]],
[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0], [-1.0, -1.0, 1.0]],
[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0], [-1.0, -1.0, 1.0]],
[[0.0, 0.0, 0.0], [-1.0, -1.0, 1.0], [1.0, 1.0, 1.0]],
[[0.0, 0.0, 0.0], [-1.0, -1.0, 1.0], [1.0, 1.0, 1.0]],
[[0.0, 0.0, 0.0], [-1.0, -1.0, 1.0], [1.0, 1.0, 1.0]],
[[0.0, 0.0, 0.0], [-1.0, -1.0, 1.0], [1.0, 1.0, 1.0]],
[[0.0, 0.0, 0.0], [-1.0, -1.0, 1.0], [1.0, 1.0, 1.0]],
[[0.0, 0.0, 0.0], [-1.0, -1.0, 1.0], [1.0, 1.0, 1.0]],
[[0.0, 0.0, 0.0], [-1.0, -1.0, 1.0], [1.0, 1.0, 1.0]],
[[0.0, 0.0, 0.0], [-1.0, -1.0, 1.0], [1.0, 1.0, 1.0]],
[[0.0, 0.0, 0.0], [-1.0, -1.0, 1.0], [1.0, 1.0, 1.0]],
[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0], [-1.0, -1.0, 1.0]],
[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0], [-1.0, -1.0, 1.0]],
[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0], [-1.0, -1.0, 1.0]],
[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0], [-1.0, -1.0, 1.0]],
[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0], [-1.0, -1.0, 1.0]],
[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0], [-1.0, -1.0, 1.0]],
[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0], [-1.0, -1.0, 1.0]],
[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0], [-1.0, -1.0, 1.0]],
[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0], [-1.0, -1.0, 1.0]],
[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0], [-1.0, -1.0, 1.0]],
[[0.0, 0.0, 0.0], [-1.0, -1.0, 1.0], [1.0, 1.0, 1.0]],
[[0.0, 0.0, 0.0], [-1.0, -1.0, 1.0], [1.0, 1.0, 1.0]]]
# initialization function: plot the background of each frame
def init():
for pt in pts:
pt.set_data([], [])
pt.set_3d_properties([])
return pts
def animate(i):
print "i: ", i
for pt, positon in zip (pts, data[i]):
x = positon[0]
y = positon[1]
z = positon[2]
pt.set_data(x, y)
pt.set_3d_properties(z)
fig.canvas.draw()
return pts
anim = animation.FuncAnimation(fig, animate, init_func=init, interval=1, frames=len(data), blit=True, repeat=False)
plt.show()
如何在屏幕上的幀的顯示涉及在
animation.FuncAnimation
「間隔」參數? (我不能讓它在不到5秒的時間內顯示50幀)此設計是處理長時間潛在30fps大量點(10+)的最佳方式嗎? (「數據」在1小時內會很大)。
我還在研究各種示例,但沒有顯示簡單的3D動畫散點圖。
謝謝。
你可能會更好地在一次調用中繪製所有點,傳遞一個顏色數組作爲'c ='參數而不是一個對象。雖然我在每幀只有3分猜測,它可能沒有什麼區別 – Eric
我想'塊傳輸= TRUE'使得'fig.canvas.draw()'不必要 – Eric
這似乎這樣的伎倆!我還沒有做出確切的測量,但我相信現在可以達到30 fps。這太棒了,謝謝。 – lolo