pyvista.DataSetAttributes.set_vectors

pyvista.DataSetAttributes.set_vectors#

DataSetAttributes.set_vectors(
vectors: MatrixLike[float],
name: str,
deep_copy: bool = False,
) None[source]#

Set the active vectors of this data attribute.

Vectors are a quantity that has magnitude and direction, such as normal vectors or a velocity field.

The vectors data must contain three components per cell or point. Use DataSetAttributes.set_scalars() when adding non-directional data.

Parameters:
vectorsMatrixLike

Data shaped (n, 3) where n matches the number of points or cells.

namestr

Name of the vectors.

deep_copybool, default: False

When True makes a full copy of the array. When False, the data references the original array without copying it.

Notes

PyVista and VTK treats vectors and scalars differently when performing operations. Vector data, unlike scalar data, is rotated along with the geometry when the DataSet is passed through a transformation filter.

When adding non-directional data (such temperature values or multi-component scalars like RGBA values), you can also use DataSetAttributes.set_scalars().

Examples

Add random vectors to a mesh as point data.

>>> import pyvista as pv
>>> import numpy as np
>>> mesh = pv.Cube()
>>> mesh.clear_data()
>>> vectors = np.random.default_rng().random((mesh.n_points, 3))
>>> mesh.point_data.set_vectors(vectors, 'my-vectors')
>>> mesh.point_data
pyvista DataSetAttributes
Association     : POINT
Active Scalars  : None
Active Vectors  : my-vectors
Active Texture  : None
Active Normals  : None
Contains arrays :
    my-vectors              float64    (8, 3)               VECTORS