In [ ]:
import k3d
import numpy as np

plot = k3d.plot()

plot += k3d.vectors(
(0,0,0,0,0,0,0,0,0),
(10,0,0,0,10,0,0,0,10),
colors=(0xff0000, 0xff0000, 0x0000ff, 0x0000ff, 0x00ff00, 0x00ff00),
labels=('x', 'y', 'z')
)

• let us avaluate a function of 3 variables on relatively large mesh
In [ ]:
T = 1.618033988749895
from numpy import sin,cos,pi
r = 4.77
zmin,zmax = -r,r
xmin,xmax = -r,r
ymin,ymax = -r,r
Nx,Ny,Nz = 80,80,80

x = np.linspace(xmin,xmax,Nx)
y = np.linspace(ymin,ymax,Ny)
z = np.linspace(zmin,zmax,Nz)
x,y,z = np.meshgrid(x,y,z,indexing='ij')

%time p = 2 - (cos(x + T*y) + cos(x - T*y) + cos(y + T*z) \
+ cos(y - T*z) + cos(z - T*x) + cos(z + T*x))

p3d_1 = k3d.marching_cubes(p,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax, zmin=zmin, zmax=zmax,\
level=0.0)
plot += p3d_1

In [ ]:
plot.display()

In [ ]:
p3d_1.color = 0x114455

• isolevel can be changed from Python side:
In [ ]:
p3d_1.level=-0.1

In [ ]:
from ipywidgets import interact, interactive, fixed
import ipywidgets as widgets

@interact(l=widgets.FloatSlider(value=-.1,min=-3,max=1.1))
def g(l):
p3d_1.level=-l

• to avoid recentering one can disable camera auto fit:
In [ ]:
plot.camera_auto_fit = False
plot.grid_auto_fit = False

• one can add other plots to the same scene:
In [ ]:
%%time
p =(x**2+y**2+z**2+2*y-1)*((x**2+y**2+z**2-2*y-1)**2-8*z**2)+16*x*z*(x**2+y**2+z**2-2*y-1)
plot += k3d.marching_cubes(p,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax, zmin=zmin, zmax=zmax, level=0.0,color=0xff0000)

In [ ]:
%%time
p = x**2 + y**2 - z**2 -0.
plot += k3d.marching_cubes(p,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax, zmin=zmin, zmax=zmax, level=0.0,color=0x00ff00)

In [ ]:


In [ ]: