Note
Click here to download the full example code
Create PolyData#
Creating a PolyData (triangulated surface) object from NumPy arrays of the vertices and faces.
import numpy as np
import pyvista as pv
A PolyData object can be created quickly from numpy arrays. The vertex array contains the locations of the points in the mesh and the face array contains the number of points of each face and the indices of the vertices which comprise that face.
# mesh points
vertices = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0.5, 0.5, -1]])
# mesh faces
faces = np.hstack([[4, 0, 1, 2, 3], [3, 0, 1, 4], [3, 1, 2, 4]]) # [square, triangle, triangle]
surf = pv.PolyData(vertices, faces)
# plot each face with a different color
surf.plot(scalars=np.arange(3), cpos=[-1, 1, 0.5])

Total running time of the script: ( 0 minutes 0.532 seconds)