set_scalars#

DataSetAttributes.set_scalars(scalars: Union[Sequence[Union[float, int]], float, int, numpy.ndarray], name='scalars', deep_copy=False)[source]#

Set the active scalars of the dataset with an array.

In VTK and PyVista, scalars are a quantity that has no direction. This can include data with multiple components (such as RGBA values) or just one component (such as temperature data).

See DataSetAttributes.set_vectors() when adding arrays that contain magnitude and direction.

Parameters
scalarssequence

A pyvista_ndarray, numpy.ndarray, list, tuple or scalar value.

namestr

Name to assign the scalars.

deep_copybool, optional

When True makes a full copy of the array.

Notes

When adding directional data (such as velocity vectors), use DataSetAttributes.set_vectors().

Examples

>>> import pyvista
>>> mesh = pyvista.Cube()
>>> mesh.clear_data()
>>> scalars = range(mesh.n_points)
>>> mesh.point_data.set_scalars(scalars, 'my-scalars')
>>> mesh.point_data
pyvista DataSetAttributes
Association     : POINT
Active Scalars  : my-scalars
Active Vectors  : None
Active Texture  : None
Active Normals  : None
Contains arrays :
    my-scalars              int64    (8,)                 SCALARS