In [ ]:
import k3d
import numpy as np

plot = k3d.plot()

plot += k3d.label('Test dynamic', (0,0,0), mode='dynamic')
plot += k3d.label('Test local', (1,0,0), mode='local')
plot += k3d.label('Test side 1', (1,1,1), mode='side')
plot += k3d.label('Test side 2 with żółć', (0,0,1), mode='side', is_html=True)

plot.display()
In [ ]:
plot.objects[0].label_box = False

Label maker

In [ ]:
import ipywidgets as widgets

plot = k3d.plot()

X, Y, Z = np.mgrid[:50, :50, :50]

scalar_field = ((X-25.0)/20.0)**2 + ((Y-25.0)/20.0)**2 + ((Z-25.0)/20.0)**2 + \
                 np.sin(X * 0.5) * 0.25 + np.cos((Y + Z) * 0.3) * 0.3

obj = k3d.marching_cubes(scalar_field.astype(np.float32), level=0.8)
plot += obj

on_top = widgets.Dropdown(options=[True, False], description='on_top')
label_box = widgets.Dropdown(options=[True, False], description='label_box')
mode = widgets.Dropdown(options=['dynamic', 'local', 'side'], description='Mode')
text = widgets.Text(description='Text', value='{(1,\\frac{5}{\\pi}, \\sqrt{2})}')

def add_label(p):
    global plot, text, mode, label_box, on_top
    plot += k3d.label(text.value, p['position'], mode=mode.value, label_box=label_box.value, on_top=on_top.value)

obj.click_callback = add_label

display(mode)
display(text)
display(on_top)
display(label_box)

plot.display()
In [ ]:
plot.mode = 'callback'

Label inspection

In [ ]:
import ipywidgets as widgets

plot = k3d.plot()

X, Y, Z = np.mgrid[:50, :50, :50]

scalar_field = ((X-25.0)/20.0)**2 + ((Y-25.0)/20.0)**2 + ((Z-25.0)/20.0)**2 + \
                 np.sin(X * 0.5) * 0.25 + np.cos((Y + Z) * 0.3) * 0.3

obj = k3d.marching_cubes(scalar_field.astype(np.float32), level=0.8)
label = k3d.label('', mode='local', color=0x0)

plot += obj
plot += label

def update_label(p):
    global label
    label.text = '\\vec{n} = \\begin{bmatrix} ' + "\\\\".join([str(v) for v in p['normal']]) +' \\end{bmatrix}'
    label.position = p['position']

obj.hover_callback = update_label

plot.display()
In [ ]:
plot.mode = 'callback'
In [ ]: