k3d.factory.marching_cubes(scalar_field, level, color=255, attribute=[], color_map=None, color_range=[], opacity_function=[], 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.

  • attribute (list, optional) – List of values used to apply color_map, by default [].

  • color_map (list, optional) – List of float quadruplets (attribute value, R, G, B) sorted by attribute value, by default None. The first quadruplet should have value 0.0, the last 1.0; R, G, B are RGB color components in the range 0.0 to 1.0.

  • color_range (list, optional) – [min_value, max_value] pair determining the levels of color attribute mapped to 0 and 1 in the colormap, by default [].

  • opacity_function (array.) – A list of float tuples (attribute value, opacity), sorted by attribute value. The first typles should have value 0.0, the last 1.0; opacity is in the range 0.0 to 1.0.

  • 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