surface#
- k3d.factory.surface(heights, color=255, wireframe=False, flat_shading=True, attribute=[], color_map=None, color_range=[], opacity=1.0, name=None, group=None, custom_data=None, compression_level=0, **kwargs)[source]#
Create a Surface drawable.
Plot a 2d function: z = f(x, y). The default domain of the scalar field is -0.5 < x, y < 0.5.
If the domain should be different, the bounding box needs to be transformed using kwargs
surface(..., bounds=[-1, 1, -1, 1])
surface(..., xmin=-10, xmax=10, ymin=-4, ymax=4)
- Parameters
heights (array_like) – Array of float values.
color (int, optional) – Hex color of the surface, 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.
attribute (list, optional) – List of values used to apply color_map, by default [].
opacity (float.) – Opacity of surface.
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 [].
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.
- Returns
Surface Drawable.
- Return type
Surface
See also
Examples#
Basic#
# Example from
# https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/35311/versions/3/previews/html/Surface_Contour_Plot.html
import k3d
import numpy as np
from numpy import sin, sqrt
x = np.linspace(-5, 5, 100, dtype=np.float32)
y = np.linspace(-5, 5, 100, dtype=np.float32)
x, y = np.meshgrid(x, y)
f = sin(sqrt(x**2 + y**2))
plt_surface = k3d.surface(f,
color=0x006394,
wireframe=True,
xmin=0, xmax=10,
ymin=0, ymax=10)
plot = k3d.plot()
plot += plt_surface
plot.display()
Colormap#
Attention
color_map must be used along with attribute and color_range in order to work correctly.
# Example from http://www2.math.umd.edu/~jmr/241/surfaces.html
import k3d
import numpy as np
from k3d.colormaps import matplotlib_color_maps
x = np.linspace(-5, 5, 100, dtype=np.float32)
y = np.linspace(-5, 5, 100, dtype=np.float32)
x, y = np.meshgrid(x, y)
f = ((x**2 - 1) * (y**2 - 4) + x**2 + y**2 - 5) / (x**2 + y**2 + 1)**2
plt_surface = k3d.surface(f * 2,
xmin=-5, xmax=5,
ymin=-5, ymax=5,
compression_level=9,
color_map=matplotlib_color_maps.Coolwarm_r,
attribute=f, color_range=[-1, 0.5])
plot = k3d.plot()
plot += plt_surface
plot.display()