DataSetFilters.warp_by_scalar

DataSetFilters.warp_by_scalar#

DataSetFilters.warp_by_scalar(
scalars: str | None = None,
*,
factor: float = 1.0,
normal: VectorLikeFloat | None = None,
inplace: bool = False,
progress_bar: bool = False,
**kwargs: Any,
) → StructuredGrid | _DataSetType[source]#

Warp the dataset’s points by a point data scalars array’s values.

This modifies point coordinates by moving points along point normals by the scalar amount times the scale factor.

Parameters:
scalarsstr, optional

Name of scalars to warp by. Defaults to currently active scalars.

factorfloat, default: 1.0

A scaling factor to increase the scaling effect. Alias scale_factor also accepted - if present, overrides factor.

normalVectorLikeFloat, optional

User specified normal. If given, data normals will be ignored and the given normal will be used to project the warp.

inplacebool, default: False

If True, the points of the given dataset will be updated.

progress_barbool, default: False

Display a progress bar to indicate progress.

**kwargsdict, optional

Accepts scale_factor instead of factor.

Returns:
pyvista.DataSet

Warped Dataset. Return type matches input, except that an ImageData or RectilinearGrid gives a StructuredGrid.

Notes#

Points are only moved along their own point normals when the dataset has them. Without point normals, or with normal given, every point is instead moved along that single fixed direction – vtkWarpScalar’s default is (0, 0, 1) – rather than radially or otherwise per point. This is easy to miss on a dataset assembled directly from coordinates, such as grid_from_sph_coords(), where the result looks like a uniform vertical shift instead of the intended radial warp. Use warp_by_vector() instead when the warp direction should vary per point but the dataset has no normals to warp along, for example using each point’s own radial direction as the vector array.

Examples#

Download Python source code | Download Jupyter notebook

First, plot the un-warped mesh.

>>> from pyvista import examples
>>> mesh = examples.download_st_helens()
>>> mesh.plot(cmap='gist_earth', show_scalar_bar=False)
../../../_images/pyvista-DataSetFilters-warp_by_scalar-c73908f4014fe895_00_00.png

Now, warp the mesh by the 'Elevation' scalars.

>>> warped = mesh.warp_by_scalar('Elevation')
>>> warped.plot(cmap='gist_earth', show_scalar_bar=False)
../../../_images/pyvista-DataSetFilters-warp_by_scalar-c73908f4014fe895_01_00.png

See Also#

warp_by_vector

Warp along a per-point direction instead of a single fixed one.