line#
- k3d.factory.line(vertices: List | ndarray | Tuple, color: int = 255, colors: List[int] = None, attribute: List | ndarray | Tuple = None, color_map: List[List[float]] | Dict[str, Any] | ndarray | None = None, color_range: List[float] = None, width: float = 0.01, opacity: float = 1.0, shader: str = 'thick', shininess: float = 50.0, radial_segments: int = 8, name: str | None = None, group: str | None = None, custom_data: Dict[str, Any] | None = None, compression_level: int = 0, **kwargs: Any) Line[source]#
Create a Line drawable for plotting segments and polylines.
- Parameters:
vertices (array_like) – Array with (x, y, z) coordinates of segment endpoints.
color (int, optional) – Hex color of the lines when colors is empty, by default _default_color.
colors (list, optional) – Array of Hex colors when attribute, color_map and color_range are empty, by default [].
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 [].
width (float, optional) – Thickness of the lines, by default 0.01.
shader ({'simple', 'thick', 'mesh'}, optional) – Display style of the lines, by default ‘thick’.
shininess (float, optional) – Shininess of object material, by default 50.0.
radial_segments (int, optional) – Number of segmented faces around the circumference of the tube, by default 8.
name (str, optional) – Object name, by default None.
group (str, optional) – Name of a group, by default None.
custom_data (dict, optional) – An object with custom data attached to object, by default None.
compression_level (int, optional) – Level of data compression [-1, 9], by default 0.
**kwargs – Additional keyword arguments passed to process_transform_arguments.
- Returns:
The created Line drawable object.
- Return type:
Line
Examples#
Basic#
import k3d
import numpy as np
t = np.linspace(-10, 10, 100,dtype=np.float32)
x = np.cos(t)
y = np.sin(t)
z = t / 5
vertices = np.vstack([x,y,z]).T
plt_line = k3d.line(vertices, width=0.1, color=0xff99cc)
plot = k3d.plot()
plot += plt_line
plot.display()
Colormap#
Attention
color_map must be used along with attribute and color_range in order to work correctly.
import k3d
import numpy as np
from k3d.colormaps import matplotlib_color_maps
t = np.linspace(-10, 10, 100,dtype=np.float32)
x = np.cos(t)
y = np.sin(t)
z = t / 5
vertices = np.vstack([x,y,z]).T
plt_line = k3d.line(vertices, width=0.2, shader='mesh',
color_map=matplotlib_color_maps.Jet,
attribute=t,
color_range=[-5, 5])
plot = k3d.plot()
plot += plt_line
plot.display()