In [1]:
import k3d
import numpy as np
from ipywidgets import interact, IntSlider

width = height = length = 3

color_map = (0xFF0000, 0x00FF00, 0x0000FF)
voxels = np.ones(width * height * length, dtype=np.uint8).reshape((length, height, width))
obj = k3d.voxels(voxels, color_map)

plot = k3d.plot(voxel_paint_color=2)
plot += obj

@interact(color=IntSlider(value=plot.voxel_paint_color, min=0, max=len(color_map)))
def color(color):
    plot.voxel_paint_color = color

plot.display()



In [2]:
obj.voxels.flatten()  # initial data


Out[2]:
array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
       1, 1, 1, 1, 1], dtype=uint8)

Edit object (add/remove some voxels)


In [3]:
plot.mode = 'change'

In [4]:
obj.fetch_data('voxels')  # this is an async operation

In [5]:
obj.voxels.flatten()  # updated data


Out[5]:
array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
       1, 1, 1, 1, 1], dtype=uint8)

In [6]:
obj.visible = False

In [7]:
obj.visible = True

In [ ]: