vectors#

k3d.factory.vectors(origins, vectors=None, colors=[], origin_color=None, head_color=None, color=255, use_head=True, head_size=1.0, labels=[], label_size=1.0, line_width=0.01, name=None, group=None, custom_data=None, compression_level=0, **kwargs)[source]#

Create a Vectors drawable representing individual 3D vectors.

For dense 3D or 2D vectors,like forming a grid, use vector_field.

Parameters
  • origins (array_like) – Array of (x, y, z) coordinates of vector origins.

  • vectors (array_like, optional) – Array of (dx, dy, dz) directions of vectors, by default None. Must have the same size as origins.

  • colors (list, optional) – Array of Hex colors of vectors, by default [].

  • origin_color (int, optional) – Hex color of vector origins when colors is empty, by default None.

  • head_color (int, optional) – Hex color of vector heads when colors is empty, by default None.

  • color (int, optional) – Hex color of the vectors when colors is empty, by default None.

  • use_head (bool, optional) – Display vector heads, by default True.

  • head_size (float, optional) – Vector heads size, by default 1.0.

  • labels (list, optional) – List of str of caption the display next tot the vectors, by default [].

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

  • line_width (float, optional) – Width of vector segments, by default 0.01.

  • 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

Vectors Drawable.

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