pyvista.DataSetAttributes.set_scalars#

DataSetAttributes.set_scalars(
scalars: ArrayLike[float],
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:
scalarsArrayLike[float]

Array of data.

namestr, default: ‘scalars’

Name to assign the scalars.

deep_copybool, default: False

When True makes a full copy of the array.

Notes

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

Complex arrays will be represented internally as a 2 component float64 array. This is due to limitations of VTK’s native datatypes.

Examples

>>> import pyvista as pv
>>> mesh = pv.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