DataObject.add_field_data#
- DataObject.add_field_data(array: ArrayLike[Any], name: str, deep: bool = True) None[source]#
Add field data.
Use field data when size of the data you wish to associate with the dataset does not match the number of points or cells of the dataset.
- Parameters:
Examples#
Download Python source code | Download Jupyter notebook
Add field data to a PolyData dataset.
>>> import pyvista as pv
>>> import numpy as np
>>> mesh = pv.Sphere()
>>> mesh.add_field_data(np.arange(10), 'my-field-data')
>>> mesh['my-field-data']
pyvista_ndarray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
Add field data to a ImageData dataset.
>>> mesh = pv.ImageData(dimensions=(2, 2, 1))
>>> mesh.add_field_data(['I could', 'write', 'notes', 'here'], 'my-field-data')
>>> mesh['my-field-data']
pyvista_ndarray(['I could', 'write', 'notes', 'here'], dtype='<U7')
Add field data to a MultiBlock dataset.
>>> blocks = pv.MultiBlock()
>>> blocks.append(pv.Sphere())
>>> blocks['cube'] = pv.Cube(center=(0, 0, -1))
>>> blocks.add_field_data([1, 2, 3], 'my-field-data')
>>> blocks.field_data['my-field-data']
pyvista_ndarray([1, 2, 3])