pyvista.Plotter.camera_position

pyvista.Plotter.camera_position#

property Plotter.camera_position: CameraPosition[source]#

Set or return the camera position of the active render window.

Examples

Return the camera’s position as a CameraPosition object.

>>> import pyvista as pv
>>> from pyvista import examples
>>> mesh = examples.download_bunny_coarse()
>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(mesh, show_edges=True, reset_camera=True)
>>> cpos = pl.camera_position

Show the camera position. This implicitly calls repr(cpos).

>>> cpos
CameraPosition(position=(0.02430, 0.0336, 0.9446),
               focal_point=(0.02430, 0.0336, -0.02225),
               viewup=(0.0, 1.0, 0.0))

Create a new CameraPosition object by copy/pasting the repr and prepending the pyvista module, i.e. pv..

>>> new_cpos = pv.CameraPosition(
...     position=(0.02430, 0.0336, 0.9446),
...     focal_point=(0.02430, 0.0336, -0.02225),
...     viewup=(0.0, 1.0, 0.0),
... )

Set the camera_position with this new object.

>>> pl.camera_position = new_cpos

Use print or str to obtain a list representation instead.

>>> print(cpos)
[(0.02430, 0.0336, 0.9446),
 (0.02430, 0.0336, -0.02225),
 (0.0, 1.0, 0.0)]

Reposition it via a list of tuples.

>>> pl.camera_position = [
...     (0.3914, 0.4542, 0.7670),
...     (0.0243, 0.0336, -0.0222),
...     (-0.2148, 0.8998, -0.3796),
... ]
>>> pl.show()
../../../_images/pyvista-Plotter-camera_position-55d05a4d43defc59_00_00.png

Set the camera position using a string and look at the 'xy' plane.

>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(mesh, show_edges=True)
>>> pl.camera_position = 'xy'
>>> pl.show()
../../../_images/pyvista-Plotter-camera_position-55d05a4d43defc59_01_00.png

Set the camera position using a string and look at the 'zy' plane.

>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(mesh, show_edges=True)
>>> pl.camera_position = 'zy'
>>> pl.show()
../../../_images/pyvista-Plotter-camera_position-55d05a4d43defc59_02_00.png

For more examples, see Cameras.