pyvista.DataSetAttributes#
- class DataSetAttributes(*args, **kwargs)[source]#
- Python friendly wrapper of vtkDataSetAttributes. - This class provides the ability to pick one of the present arrays as the currently active array for each attribute type by implementing a - dictlike interface.- When adding data arrays but not desiring to set them as active scalars or vectors, use - DataSetAttributes.set_array().- When adding directional data (such as velocity vectors), use - DataSetAttributes.set_vectors().- When adding non-directional data (such as temperature values or multi-component scalars like RGBA values), use - DataSetAttributes.set_scalars().- Changed in version 0.32.0: The - []operator no longer allows integers. Use- DataSetAttributes.get_array()to retrieve an array using an index.- Parameters:
- vtkobjectvtkFieldData
- The vtk object to wrap as a :class:~pyvista.DataSetAttribute`, usually an instance of vtkCellData, vtkPointData, or vtkFieldData. 
- datasetvtkDataSet
- The vtkDataSet containing the vtkobject. 
- associationFieldAssociation
- The array association type of the vtkobject. 
 
 - Notes - When printing out the point arrays, you can see which arrays are the active scalars, vectors, normals, and texture coordinates. In the arrays list, - SCALARSdenotes that these are the active scalars,- VECTORSdenotes that these arrays are tagged as the active vectors data (i.e. data with magnitude and direction) and so on.- Examples - Store data with point association in a DataSet. - >>> import pyvista as pv >>> mesh = pv.Cube() >>> mesh.point_data['my_data'] = range(mesh.n_points) >>> data = mesh.point_data['my_data'] >>> data pyvista_ndarray([0, 1, 2, 3, 4, 5, 6, 7]) - Change the data array and show that this is reflected in the DataSet. - >>> data[:] = 0 >>> mesh.point_data['my_data'] pyvista_ndarray([0, 0, 0, 0, 0, 0, 0, 0]) - Remove the array. - >>> del mesh.point_data['my_data'] >>> 'my_data' in mesh.point_data False - Print the available arrays from dataset attributes. - >>> import numpy as np >>> mesh = pv.Plane(i_resolution=1, j_resolution=1) >>> mesh.point_data.set_array(range(4), 'my-data') >>> mesh.point_data.set_array(range(5, 9), 'my-other-data') >>> vectors0 = np.random.default_rng().random((4, 3)) >>> mesh.point_data.set_vectors(vectors0, 'vectors0') >>> vectors1 = np.random.default_rng().random((4, 3)) >>> mesh.point_data.set_vectors(vectors1, 'vectors1') >>> mesh.point_data pyvista DataSetAttributes Association : POINT Active Scalars : None Active Vectors : vectors1 Active Texture : TextureCoordinates Active Normals : Normals Contains arrays : Normals float32 (4, 3) NORMALS TextureCoordinates float32 (4, 2) TCOORDS my-data int64 (4,) my-other-data int64 (4,) vectors1 float64 (4, 3) VECTORS vectors0 float64 (4, 3) - Methods - Remove all arrays in this object. - DataSetAttributes.get(key[, value])- Return the value of the item with the specified key. - Get an array in this object. - Return a list of (array name, array value) tuples. - Return the names of the arrays as a list. - DataSetAttributes.pop(key[, default])- Remove an array and return it. - Remove an array. - DataSetAttributes.set_array(data, name[, ...])- Add an array to this object. - DataSetAttributes.set_scalars(scalars[, ...])- Set the active scalars of the dataset with an array. - DataSetAttributes.set_vectors(vectors, name)- Set the active vectors of this data attribute. - DataSetAttributes.update(array_dict[, copy])- Update arrays in this object from another dictionary or dataset attributes. - Return the arrays as a list. - Attributes - Return the normals. - Return the name of the normals array. - Return the active scalars. - Return name of the active scalars. - Return the active texture coordinates array. - Return the name of the active texture coordinates array. - Return the active vectors as a pyvista_ndarray. - Return name of the active vectors. - Return the length data should be when added to the dataset.