pyvista.vector_poly_data

pyvista.vector_poly_data#

vector_poly_data(
orig: VectorLike[float] | MatrixLike[float],
vec: VectorLike[float] | MatrixLike[float],
) PolyData[source]#

Create a pyvista.PolyData object composed of vectors.

Parameters:
origarray_like[float]

Array of vector origins.

vecarray_like[float]

Array of vectors.

Returns:
pyvista.PolyData

Mesh containing the orig points along with the 'vectors' and 'mag' point arrays representing the vectors and magnitude of the vectors at each point.

Examples

Create basic vector field. This is a point cloud where each point has a vector and magnitude attached to it.

>>> import pyvista as pv
>>> import numpy as np
>>> x, y = np.meshgrid(np.linspace(-5, 5, 10), np.linspace(-5, 5, 10))
>>> points = np.vstack((x.ravel(), y.ravel(), np.zeros(x.size))).T
>>> u = x / np.sqrt(x**2 + y**2)
>>> v = y / np.sqrt(x**2 + y**2)
>>> vectors = np.vstack((u.ravel() ** 3, v.ravel() ** 3, np.zeros(u.size))).T
>>> pdata = pv.vector_poly_data(points, vectors)
>>> pdata.point_data.keys()
['vectors', 'mag']

Convert these to arrows and plot it.

>>> pdata.glyph(orient='vectors', scale='mag').plot()
../../../_images/pyvista-vector_poly_data-1_00_00.png