pyvista.DataSetAttributes.set_array#
- DataSetAttributes.set_array( ) None [source]#
Add an array to this object.
Use this method when adding arrays to the DataSet. If needed, these arrays can later be assigned to become the active scalars, vectors, normals, or texture coordinates with:
- Parameters:
Notes
You can simply use the
[]
operator to add an array to the dataset. Note that this will automatically become the active scalars.Examples
Add a point array to a mesh.
>>> import pyvista as pv >>> mesh = pv.Cube() >>> data = range(mesh.n_points) >>> mesh.point_data.set_array(data, 'my-data') >>> mesh.point_data['my-data'] pyvista_ndarray([0, 1, 2, 3, 4, 5, 6, 7])
Add a cell array to a mesh.
>>> cell_data = range(mesh.n_cells) >>> mesh.cell_data.set_array(cell_data, 'my-data') >>> mesh.cell_data['my-data'] pyvista_ndarray([0, 1, 2, 3, 4, 5])
Add field data to a mesh.
>>> field_data = range(3) >>> mesh.field_data.set_array(field_data, 'my-data') >>> mesh.field_data['my-data'] pyvista_ndarray([0, 1, 2])