DataSetAttributes.set_vectors#
- DataSetAttributes.set_vectors( ) 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:
- vectors
MatrixLike Data shaped
(n, 3)where n matches the number of points or cells.- name
str Name of the vectors.
- deep_copybool, default:
False When
Truemakes a full copy of the array. WhenFalse, the data references the original array without copying it.
- vectors
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#
Download Python source code | Download Jupyter notebook
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