voxels#
- k3d.factory.voxels(voxels: List | ndarray | Tuple, color_map: List[List[float]] | Dict[str, Any] | ndarray | None = None, wireframe: bool = False, outlines: bool = True, outlines_color: int = 0, opacity: float = 1.0, bounds: List | ndarray | Tuple | None = None, name: str | None = None, group: str | None = None, custom_data: Dict[str, Any] | None = None, compression_level: int = 0, **kwargs: Any) Voxels[source]#
See also
Examples#
Basic#
import k3d
import numpy as np
voxels = np.array([[[0, 1],
[1, 2]],
[[2, 2],
[1, 1]]]).astype(np.uint8)
plt_voxels = k3d.voxels(voxels,
color_map=[0xfdc192, 0xa15525],
outlines_color=0xffffff)
plot = k3d.plot()
plot += plt_voxels
plot.display()
Shapes#
import k3d
import numpy as np
t = np.linspace(-1.5, 1.5, 50, dtype=np.float32)
x, y, z = np.meshgrid(t, t, t, indexing='ij')
R = 1
r = 0.5
eq_heart = (x**2 + (9/4 * y**2) + z**2 - 1)**3 - (x**2 * z**3) - (9/200 * y**2 * z**3)
eq_torus = (x**2 + y**2 + z**2 + R**2 - r**2)**2 - 4 * R**2 * (x**2 + y**2)
voxels_heart = np.zeros_like(eq_heart).astype(np.uint8)
voxels_torus = np.zeros_like(eq_torus).astype(np.uint8)
voxels_heart[eq_heart < 0] = 1
voxels_torus[eq_torus > 0] = 1
plt_voxels_heart = k3d.voxels(voxels_heart,
color_map=[0xbc4749],
outlines=False,
bounds=[-1.5, 1.5,-1.5, 1.5,-1.5, 1.5])
plt_voxels_torus = k3d.voxels(voxels_torus,
color_map=[0x3b60e4],
outlines=False,
wireframe=True,
bounds=[-1.5, 1.5,-1.5, 1.5,-1.5, 1.5],
translation=[0, 0, -3.5])
plot = k3d.plot()
plot += plt_voxels_heart
plot += plt_voxels_torus
plot.display()