text2d#

k3d.factory.text2d(text, position=(0, 0), color=255, size=1.0, reference_point='lt', label_box=True, is_html=False, name=None, group=None, custom_data=None, compression_level=0)[source]#

Create a Text2d drawable for 2D-positioned (viewport bound, OSD) labels.

Parameters
  • text (str or list of str) – Text content.

  • position (tuple, optional) – (rx, ry) text position ratios in range (0, 1) - relative to canvas size, by default (0, 0). If n text is pass position should contain 2*n elements .

  • color (int, optional) – Hex color of the text, by default _default_color.

  • reference_point (str, optional) –

    Two-letter string representing text alignment, by default “lb”.

    First letters

    • l – left

    • c – center

    • r – right

    Second letters

    • t – top

    • c – center

    • b – bottom

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

  • label_box (bool, optional) – Label background box, by default True.

  • is_html (bool, optional) – Interprete text as HTMl instead of KaTeX, by default False.

  • 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

Text2d Drawable.

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()