Let us draw a trajectory of N steps of an approximation to the Wiener Process in three dimensions.
Below, a blue thin line is a trajectory and the total displacement is shown with red thick line.
Line takes data as an array of coordinates [number_of_points,3].
In [1]:
import numpy as np
import k3d
plot = k3d.plot(camera_auto_fit=False)
N = 10000
traj = np.cumsum(np.random.randn(N,3).astype(np.float32),axis=0)
plt_line = k3d.line(traj, shader='mesh', width=0.5)
plt_line2 = k3d.line([traj[0],traj[-1]],shader='mesh', width=2.5, color=0xff0000)
plot += plt_line
plot += plt_line2
plot.display()
The update of vertices can be easily done by updating attribute of an object. For example we can generate other realization of the Wiener process:
In [2]:
plot.camera_auto_fit = False
plot.grid_auto_fit = False
In [ ]:
import time
for i in range(40):
traj = np.cumsum(np.random.randn(N,3).astype(np.float32),axis=0)
plt_line.vertices = traj
plt_line2.vertices = [traj[0],traj[-1]]
time.sleep(1)