pyvista.DataSetAttributes.set_scalars#
- DataSetAttributes.set_scalars(scalars: Sequence[float | int | number] | float | int | number | 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:
- scalars
float| array_like[float] A
pyvista.pyvista_ndarray,numpy.ndarray,list,tupleor scalar value.- name
str, default: ‘scalars’ Name to assign the scalars.
- deep_copybool, default:
False When
Truemakes a full copy of the array.
- scalars
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 >>> 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