class PolyData(var_inp: vtkPolyData | str | ndarray[Any, dtype[number]] | Sequence[ndarray[Any, dtype[number]] | Sequence[int | float]] = None, faces: ndarray[Any, dtype[integer]] | Sequence[int] | None = None, n_faces: int | None = None, lines: ndarray[Any, dtype[integer]] | Sequence[int] | None = None, n_lines: int | None = None, strips: ndarray[Any, dtype[integer]] | Sequence[int] | None = None, n_strips: int | None = None, deep: bool = False, force_ext: str | None = None, force_float: bool | None = True, verts: ndarray[Any, dtype[integer]] | Sequence[int] | None = None, n_verts: int | None = None)[source]#

Dataset consisting of surface geometry (e.g. vertices, lines, and polygons).

Can be initialized in several ways:

  • Create an empty mesh

  • Initialize from a vtk.vtkPolyData

  • Using vertices

  • Using vertices and faces

  • From a file

var_inpvtk.vtkPolyData, str, sequence, optional

Flexible input type. Can be a vtk.vtkPolyData, in which case this PolyData object will be copied if deep=True and will be a shallow copy if deep=False.

Also accepts a path, which may be local path as in 'my_mesh.stl' or global path like '/tmp/my_mesh.ply' or 'C:/Users/user/my_mesh.ply'.

Otherwise, this must be a points array or list containing one or more points. Each point must have 3 dimensions. If faces, lines, strips, and verts are all None, then the PolyData object will be created with vertex cells with n_verts equal to the number of points.

facessequence, optional

Face connectivity array. Faces must contain padding indicating the number of points in the face. For example, the two faces [10, 11, 12] and [20, 21, 22, 23] will be represented as [3, 10, 11, 12, 4, 20, 21, 22, 23]. This lets you have an arbitrary number of points per face.

When not including the face connectivity array, each point will be assigned to a single vertex. This is used for point clouds that have no connectivity.

n_facesint, optional

Number of faces in the faces connectivity array. While optional, setting this speeds up the creation of the PolyData.

linessequence, optional

The line connectivity array. Like faces, this array requires padding indicating the number of points in a line segment. For example, the two line segments [0, 1] and [1, 2, 3, 4] will be represented as [2, 0, 1, 4, 1, 2, 3, 4].

n_linesint, optional

Number of lines in the lines connectivity array. While optional, setting this speeds up the creation of the PolyData.

stripssequence, optional

Triangle strips connectivity array. Triangle strips require an initial triangle, and the following points of the strip. Each triangle is built with the new point and the two previous points. Just as in lines and faces, this array requires a padding indicating the number of points. For example, a single triangle strip of [0, 1, 2, 3, 6, 7, 4, 5, 0, 1] requires padding of 10 and should input as [10, 0, 1, 2, 3, 6, 7, 4, 5, 0, 1].

n_stripsint, optional

Number of strips in the strips connectivity array. While optional, setting this speeds up the creation of the PolyData.

deepbool, optional

Whether to copy the inputs, or to create a mesh from them without copying them. Setting deep=True ensures that the original arrays can be modified outside the mesh without affecting the mesh. Default is False.

force_extstr, optional

If initializing from a file, force the reader to treat the file as if it had this extension as opposed to the one in the file.

force_floatbool, optional

Casts the datatype to float32 if points datatype is non-float. Default True. Set this to False to allow non-float types, though this may lead to truncation of intermediate floats when transforming datasets.

vertssequence, optional

The verts connectivity array. Like faces, this array requires padding indicating the number of vertices in each cell. For example, [1, 0, 1, 1, 1, 2] indicates three vertex cells each with one point, and [2, 0, 1, 2, 2, 3] indicates two polyvertex cells each with two points.

n_vertsint, optional

Number of verts in the verts connectivity array. While optional, setting this speeds up the creation of the PolyData.


>>> import vtk
>>> import numpy as np
>>> from pyvista import examples
>>> import pyvista as pv

Create an empty mesh.

>>> mesh = pv.PolyData()

Initialize from a vtk.vtkPolyData object.

>>> vtkobj = vtk.vtkPolyData()
>>> mesh = pv.PolyData(vtkobj)

Initialize from just points, creating vertices

>>> points = np.array([[0, 0, 0], [1, 0, 0], [1, 0.5, 0], [0, 0.5, 0]])
>>> mesh = pv.PolyData(points)

Initialize from points and faces, creating polygonal faces.

>>> faces = np.hstack([[3, 0, 1, 2], [3, 0, 3, 2]])
>>> mesh = pv.PolyData(points, faces)

Initialize from points and lines.

>>> lines = np.hstack([[2, 0, 1], [2, 1, 2]])
>>> mesh = pv.PolyData(points, lines=lines)

Initialize from points and triangle strips.

>>> strips = np.hstack([[4, 0, 1, 3, 2]])
>>> mesh = pv.PolyData(points, strips=strips)

It is also possible to create with multiple cell types.

>>> verts = [1, 0]
>>> lines = [2, 1, 2]
>>> mesh = pv.PolyData(points, verts=verts, lines=lines)

Initialize from a filename.

>>> mesh = pv.PolyData(examples.antfile)

See Create PolyData for more examples.


PolyData.from_regular_faces(points, faces[, ...])

Alternate pyvista.PolyData convenience constructor from point and regular face arrays.[, binary, texture, ...])

Write a surface mesh to disk.


Global opt-in to strict n_faces.



Return the cell normals.


Return the cell normals.


Return the connectivity array of the faces of this PolyData.


Return if all the faces of the pyvista.PolyData are triangles.


Return if the mesh is manifold (no open edges).


Return a pointer to the lines as a numpy array.


Return the number of cells.


Return the number of polygonal faces.


Return the number of lines.


Return the number of open edges on this mesh.


Return the number of strips.


Return the number of vertices.


Return the obbTree of the polydata.


Return the point normals.


Return a face array of point indices when all faces have the same size.


Return a pointer to the strips as a numpy array.


Get the vertex cells.


Return the approximate volume of the dataset.