Axes Objects#

PyVista has many axes objects which can be used for plotting. This example highlights many of these objects and shows how to use them with related plotting methods.

from __future__ import annotations

import pyvista as pv
from pyvista import examples

Cube Axes#

Show axes bounds as a cube with CubeAxesActor.

mesh = examples.download_bunny_coarse()

pl = pv.Plotter()
pl.add_mesh(mesh)
axes = pv.CubeAxesActor(camera=pl.camera)
axes.bounds = mesh.bounds
pl.add_actor(axes)
pl.background_color = pv.Color('paraview')
pl.show()
axes objects

Adding the axes like this can be a bit cumbersome since the camera, bounds, and color must be set manually. Instead, use show_bounds() to add a CubeAxesActor with pre-configured parameters.

axes objects

Alternatively, use show_grid(). This also adds a CubeAxesActor to the plot but with different default options.

axes objects

Arrow Axes#

Arrow-style axes include AxesActor, AxesAssembly, and AxesAssemblySymmetric.

AxesActor is primarily intended for use as an orientation widget (see next section), but can also be added to a plot as a normal actor. Use add_axes_at_origin() to add AxesActor at the origin.

axes objects

The axes are too large and should be scaled down. Transformations with AxesActor are possible, but with some caveats:

  • The bounds of AxesActor are hard-coded as +/- 1, which makes it challenging to configure the camera bounds for the plot.

  • The user matrix must be used for transformations (scale and position properties do not work).

Create new axes, disable its bounds, and apply a scaling Transform.

Plot the axes with a mesh. Note that since the bounds of the axes are not used, the tip of the z-axis appears clipped, which is not ideal.

axes objects

Instead of using AxesActor, AxesAssembly is recommended for positioning axes in a scene.

axes objects

Alternatively, use AxesAssemblySymmetric for adding symmetric axes to a scene.

axes objects

Axes Widgets#

Any actor can also be used as an axes orientation widget. Here, we demonstrate using four separate axes widgets:

  1. Use add_axes() to add an arrow-style orientation widget. The widget uses AxesActor by default.

  2. Use add_box_axes() to add a box-style orientation widget.

  3. Use add_north_arrow_widget() to add a north arrow orientation widget.

  4. Add AxesAssemblySymmetric as a custom orientation widget using add_orientation_widget().

# Load a dataset
mesh = examples.load_airplane()

# Create a plotter with four linked views.
viewport = (0, 0, 0.5, 0.5)
pl = pv.Plotter(shape=(2, 2))
pl.link_views()

# Add arrow-style axes
pl.subplot(0, 0)
pl.add_mesh(mesh)
pl.add_axes(viewport=viewport)

# Add box-style axes
pl.subplot(0, 1)
pl.add_mesh(mesh)
pl.add_box_axes(viewport=viewport)

# Add north arrow
pl.subplot(1, 0)
pl.add_mesh(mesh)
pl.add_north_arrow_widget(viewport=viewport)

# Add symmetric arrow-style axes
pl.subplot(1, 1)
pl.add_mesh(mesh)
axes = pv.AxesAssemblySymmetric(label_size=25)
pl.add_orientation_widget(axes, viewport=viewport)

pl.show()
#
axes objects

Tags: plot

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

Gallery generated by Sphinx-Gallery