save#, binary=True, texture=None)[source]#

Write a surface mesh to disk.

Written file may be an ASCII or binary ply, stl, or vtk mesh file. If ply or stl format is chosen, the face normals are computed in place to ensure the mesh is properly saved.


Filename of mesh to be written. File type is inferred from the extension of the filename unless overridden with ftype. Can be one of many of the supported the following types ('.ply', '.stl', '.vtk).

binarybool, optional

Writes the file as binary when True and ASCII when False.

texturestr, numpy.ndarray, optional

Write a single texture array to file when using a PLY file. Texture array must be a 3 or 4 component array with the datatype np.uint8. Array may be a cell array or a point array, and may also be a string if the array already exists in the PolyData.

If a string is provided, the texture array will be saved to disk as that name. If an array is provided, the texture array will be saved as 'RGBA' if the array contains an alpha channel (i.e. 4 component array), or as 'RGB' if the array is just a 3 component array.


This feature is only available when saving PLY files.


Binary files write much faster than ASCII and have a smaller file size.


Save a mesh as a STL.

>>> import pyvista
>>> sphere = pyvista.Sphere()

Save a mesh as a PLY.

>>> sphere = pyvista.Sphere()

Save a mesh as a PLY with a texture array. Here we also create a simple RGB array representing the texture.

>>> import numpy as np
>>> sphere = pyvista.Sphere()
>>> texture = np.zeros((sphere.n_points, 3), np.uint8)
>>> texture[:, 1] = np.arange(sphere.n_points)[::-1]  # just blue channel
>>> sphere.point_data['my_texture'] = texture
>>>'my_mesh.ply', texture='my_texture')  

Alternatively, provide just the texture array. This will be written to the file as 'RGB' since it does not contain an alpha channel.

>>>'my_mesh.ply', texture=texture)  

Save a mesh as a VTK file.

>>> sphere = pyvista.Sphere()