label#

k3d.factory.label(text: str, position: Tuple[float, float, float] = (0, 0, 0), color: int = 255, on_top: bool = True, size: float = 1.0, max_length: float = 0.8, mode: str = 'dynamic', is_html: bool = False, label_box: bool = True, name: str | None = None, group: str | None = None, custom_data: Dict[str, Any] | None = None, compression_level: int = 0, visible: bool = True, **kwargs: Any) → Label[source]#

Create a Label drawable, a text with a line pointing at a position in space.

Parameters:
  • text (str or list of str) – Content of the text.

  • position (list, optional) – (x, y, z) coordinates of text position, by default (0, 0, 0). If n text is pass position should contain 3*n elements . Default is (0, 0, 0).

  • color (int, optional) – Packed RGB color of the text (0xff0000 is red, 0xff is blue). Default is 255.

  • on_top (bool, optional) – Render order with 3d object Default is True.

  • size (float, optional) – Font size in ‘em’ HTML units. Default is 1.0.

  • max_length (float, optional) – Maximum length of the line connecting the label to its position, as a fraction of the canvas. Default is 0.8.

  • mode (str, optional) – How the label is placed: ‘dynamic’, ‘local’ or ‘side’. Default is ‘dynamic’.

  • is_html (bool, optional) – Whether text should be interpreted as HTML insted of KaTeX. Default is False.

  • label_box (bool, optional) – Label background box. Default is True.

  • name (str, optional) – A name of the object. Default is None.

  • group (str, optional) – A name of a group. Default is None.

  • custom_data (dict, optional) – An object with custom data attached to object. Default is None.

  • compression_level (int, optional) – Level of compression [-1, 9]. Default is 0.

  • visible (bool, optional) – Whether the object is drawn. Default is True.

  • **kwargs – Additional keyword arguments passed to process_transform_arguments.

Returns:

The created Label object.

Return type:

Label

See also

Examples#

Basic#

import k3d

plt_label1 = k3d.label('Insert text here',
                        position=(1, 1, 1))
plt_label2 = k3d.label('Insert text here (HTML)',
                        position=(-1, -1, -1),
                        is_html=True)

plot = k3d.plot()
plot += plt_label1
plot += plt_label2
plot.display()

Modes#

import k3d

plt_points = k3d.points([[1, 1, 1], [0, 0, 0], [-1, -1, -1]],
                        point_size=0.5,
                        shader='flat',
                        colors=[0xff0000, 0x00ff00, 0x0000ff])

plt_label_dynamic = k3d.label('Dynamic',
                              position=(1, 1, 1),
                              mode='dynamic',
                              label_box=False,
                              color=0xff0000)
plt_label_local = k3d.label('Local',
                            position=(0, 0, 0),
                            mode='local',
                            label_box=False,
                            color=0x00ff00)
plt_label_side = k3d.label('Side',
                            position=(-1, -1, -1),
                            mode='side',
                            label_box=False,
                            color=0x0000ff)

plot = k3d.plot()
plot += plt_points
plot += plt_label_dynamic
plot += plt_label_local
plot += plt_label_side
plot.display()