add_field_data

MultiBlock.add_field_data(array: numpy.ndarray, name: str, deep=True)

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
arraysequence

Array of data to add to the dataset as a field array.

namestr

Name to assign the field array.

deepbool, optional

Perform a deep copy of the data when adding it to the dataset. Default True.

Examples

Add field data to a PolyData dataset.

>>> import pyvista
>>> import numpy as np
>>> mesh = pyvista.Sphere()
>>> mesh.add_field_data(np.arange(10), 'my-field-data')
>>> mesh['my-field-data']
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

Add field data to a UniformGrid dataset.

>>> mesh = pyvista.UniformGrid((2, 2, 1))
>>> mesh.add_field_data(['I could', 'write', 'notes', 'here'], 
...                      'my-field-data')
>>> mesh['my-field-data']
array(['I could', 'write', 'notes', 'here'], dtype='<U7')

Add field data to a MultiBlock dataset.

>>> blocks = pyvista.MultiBlock()
>>> blocks.append(pyvista.Sphere())
>>> blocks["cube"] = pyvista.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])