vectors#

k3d.factory.vectors(origins: List | ndarray | Tuple, vectors: List | ndarray | Tuple | None = None, colors: List[int] = None, origin_color: int | None = None, head_color: int | None = None, color: int | None = None, use_head: bool = True, head_size: float = 1.0, labels: List[str] = None, label_size: float = 1.0, line_width: float = 0.01, name: str | None = None, group: str | None = None, custom_data: Dict[str, Any] | None = None, compression_level: int = 0, visible: bool = True, **kwargs: Any) → Vectors[source]#

Create a Vectors drawable for plotting arrows from explicit origins.

Parameters:
  • origins (array_like) – Array of (x, y, z) coordinates the vectors start at.

  • vectors (array_like, optional) – Array of (dx, dy, dz) components, one per origin. Default is None.

  • colors (array_like, optional) – Twice the length of vectors array of int: packed RGB colors (0xff0000 is red, 0xff is blue). The array has consecutive pairs (origin_color, head_color) for vectors in row-major order. Default is None.

  • origin_color (int, optional) – Packed RGB color of the origins (0xff0000 is red, 0xff is blue), default: same as color. Default is None.

  • head_color (int, optional) – Packed RGB color of the vector heads (0xff0000 is red, 0xff is blue), default: same as color. Default is None.

  • color (int, optional) – Packed RGB color of the vectors (0xff0000 is red, 0xff is blue), used for whichever of origin_color and head_color is not given. Both multiply colors. Default is 255, or white when colors is given.

  • use_head (bool, optional) – Whether vectors should display an arrow head. Default is True.

  • head_size (float, optional) – The size of the arrow heads. Default is 1.0.

  • labels (list, optional) – Array of strings displayed at the middle of each vector. Default is None.

  • label_size (float, optional) – Font size of the labels in em HTML units. Default is 1.0.

  • line_width (float, optional) – Width of the vector segments. Default is 0.01.

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

Return type:

Vectors

See also

Examples#

Basic#

import k3d
import numpy as np

o = np.array([[0, 0, 0],
              [2, 3, 4]]).astype(np.float32)

v = np.array([[1, 1, 1],
              [-2, -2, -2]]).astype(np.float32)

plt_vectors = k3d.vectors(origins=o,
                          vectors=v,
                          colors=[0x000000, 0xde49a1,
                                  0x000000, 0x40826d])

plot = k3d.plot()
plot += plt_vectors
plot.display()

Labels#

import k3d
import numpy as np

o = np.array([[1, 2, 3],
              [2, -3, 0]]).astype(np.float32)

v = np.array([[1, 1, 1],
              [-4, 2, 3]]).astype(np.float32)

labels = ['(1, 1, 1)', '(2, -3, 0)']

plt_vectors = k3d.vectors(origins=o,
                          vectors=v,
                          origin_color=0x000000,
                          head_color=0x488889,
                          line_width=0.2,
                          use_head=False,
                          labels=labels)

plot = k3d.plot()
plot += plt_vectors
plot.display()