DataObject.add_field_data#
- DataObject.add_field_data(array: _AnyArrayLike, name: str, *, deep: bool = True) None[source]#
Add field data.
Deprecated since version 0.50: Setting a scalar is deprecated. Use
user_dictto store scalar metadata.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:
- array
numpy.ndarray| sequence Array of data to add to the dataset as a field array. Field data is not tied to the geometry, so numeric, boolean, and string data are all accepted.
- name
str Name to assign the field array.
- deepbool, default:
True Perform a deep copy of the data when adding it to the dataset.
- array
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])