text2d#

k3d.factory.text2d(text: str, position: Tuple[float, float] = (0, 0), color: int = 255, size: float = 1.0, reference_point: str = 'lt', label_box: bool = True, is_html: bool = False, name: str | None = None, group: str | None = None, custom_data: Dict[str, Any] | None = None, compression_level: int = 0, visible: bool = True) → Text2d[source]#

Create a Text2d drawable, rendered with KaTeX at a fixed place on the canvas.

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

  • position (list, optional) – Ratios (r_x, r_y) of the text’s position in range (0, 1) - relative to canvas size. If n text is pass position should contain 2*n elements . Default is (0, 0).

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

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

  • reference_point (str, optional) – Two-letter string representing the text’s alignment. First letter ‘’l’, ‘c’ or ‘r’’ left, center or right Second letter ‘’t’, ‘c’ or ‘b’’ top, center or bottom. Default is ‘lt’.

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

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

  • 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.

Returns:

The created Text2d object.

Return type:

Text2d

Examples#

Basic#

import k3d

plt_text1 = k3d.text2d('Insert text here',
                      position=(0, 0))
plt_text2 = k3d.text2d('Insert text here (HTML)',
                      position=(0, 0.1),
                      is_html=True)

plot = k3d.plot()
plot += plt_text1
plot += plt_text2
plot.display()

Positions#

import k3d

plt_text_0_0 = k3d.text2d('(0,0)',
                          position=(0, 0),
                          reference_point='lt')
plt_text_0_05 = k3d.text2d('(0,0.5)',
                          position=(0, 0.5),
                          reference_point='lc')
plt_text_0_1 = k3d.text2d('(0,1)',
                          position=(0, 1),
                          reference_point='lb')
plt_text_05_0 = k3d.text2d('(0.5,0)',
                          position=(0.5, 0),
                          reference_point='ct')
plt_text_1_0 = k3d.text2d('(1,0)',
                          position=(1, 0),
                          reference_point='rt')
plt_text_1_05 = k3d.text2d('(1,0.5)',
                          position=(1, 0.5),
                          reference_point='rc')
plt_text_1_1 = k3d.text2d('(1,1)',
                          position=(1, 1),
                          reference_point='rb')
plt_text_05_1 = k3d.text2d('(0.5,1)',
                          position=(0.5, 1),
                          reference_point='cb')
plt_text_05_05 = k3d.text2d('(0.5,0.5)',
                            position=(0.5, 0.5),
                            reference_point='cc')

plot = k3d.plot()
plot += plt_text_0_0
plot += plt_text_0_05
plot += plt_text_0_1
plot += plt_text_05_0
plot += plt_text_1_0
plot += plt_text_1_05
plot += plt_text_1_1
plot += plt_text_05_1
plot += plt_text_05_05
plot.display()