line#
- k3d.factory.line(vertices, color=255, colors=[], attribute=[], color_map=None, color_range=[], width=0.01, opacity=1.0, shader='thick', radial_segments=8, name=None, group=None, custom_data=None, compression_level=0, **kwargs)[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', 'think', 'mesh'}, optional) – Display style of the lines, by default thick.
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) – 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
Line Drawable.
- 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()