There are two ways of changing data in the plot:
{t1:data1,t2:data2,...}
import k3d
import numpy as np
x = np.random.randn(100,3).astype(np.float32)
plot = k3d.plot(name='points')
plt_points = k3d.points(positions=x, point_size=0.2, shader='3d')
plot += plt_points
plot.display()
Output()
The Python backend can update attribute of any plot object in K3D-jupyter.
from time import sleep
for t in range(10):
plt_points.positions = x - t/10*x/np.linalg.norm(x,axis=-1)[:,np.newaxis]
sleep(0.5)
In this case it is possible to play an animation using only frontend. Time is a string denoting wall time.
plt_points.positions = {str(t):x - t/10*x/np.linalg.norm(x,axis=-1)[:,np.newaxis] for t in range(10)}
The animation can be controlled from GUI or by several attributes:
plot.start_auto_play() # plot.stop_auto_play()
The number of frames which are played can be inspected or set with plot.fps attribute.
plot.fps
25.0
One can programatically change or read the time in the animation using:
plot.time
6.920000000000005