k3d.factory.marching_cubes(scalar_field, level, color=255, wireframe=False, flat_shading=True, opacity=1.0, spacings_x=[], spacings_y=[], spacings_z=[], name=None, group=None, custom_data=None, compression_level=0, **kwargs)[source]#

Create a MarchingCubes drawable.

Plot an isosurface of a scalar field obtained through Marching cubes algorithm. The default domain of the scalar field is -0.5 < x, y, z < 0.5.

If the domain should be different, the bounding box needs to be transformed using kwargs

  • marching_cubes(..., bounds=[-1, 1, -1, 1, -1, 1])

  • marching_cubes(..., xmin=-10, xmax=10, ymin=-4, ymax=4, zmin=0, zmax=20)

  • marching_cubes(..., scaling=[width, height, length])

  • scalar_field (array_like) – 3D scalar field of values.

  • level (float) – Value at the computed isosurface.

  • color (int, optional) – Hex color of the isosurface, by default _default_color.

  • wireframe (bool, optional) – Display the mesh as wireframe, by default False.

  • flat_shading (bool, optional) – Display the mesh with flat shading, by default True.

  • opacity (float, optional) – Opacity of the mesh, by default 1.0.

  • spacings_x (list, optional) – Spacings in x axis, by default []. Should match scalar_field shape.

  • spacings_y (list, optional) – Spacings in y axis, by default []. Should match scalar_field shape.

  • spacings_z (list, optional) – Spacings in z axis, by default []. Should match scalar_field shape.

  • name (str, optional) – Object name, by default None.

  • group (str, optional) – Name of a group, by default None.

  • custom_data (dict) – A object with custom data attached to object.

  • compression_level (int, optional) – Level of data compression [-1, 9], by default 0.

  • **kwargs – For other keyword-only arguments, see process_transform_arguments.


MarchingCubes Drawable.

Return type



Sinus cube#

# Example from

import k3d
import numpy as np
from numpy import sin

t = np.linspace(-5, 5, 100, dtype=np.float32)
x, y, z = np.meshgrid(t, t, t, indexing='ij')

scalars = sin(x*y + x*z + y*z) + sin(x*y) + sin(y*z) + sin(x*z) - 1

plt_marching = k3d.marching_cubes(scalars, level=0.0,
                                  xmin=0, xmax=1,
                                  ymin=0, ymax=1,
                                  zmin=0, zmax=1,

plot = k3d.plot()
plot += plt_marching