1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
"""
.. _bounds_example:
Plotting Bounds
~~~~~~~~~~~~~~~
This example demonstrates to show bounds within a :class:`pyvista.Plotter`
using :func:`show_grid() <pyvista.Plotter.show_grid>`
"""
# sphinx_gallery_thumbnail_number = 2
from __future__ import annotations
import pyvista as pv
from pyvista import examples
# %%
# Show All Bounds
# ~~~~~~~~~~~~~~~
# In this plot we show the bounds for all axes by setting ``location='all'``.
plotter = pv.Plotter()
plotter.add_mesh(pv.Sphere(), smooth_shading=True)
plotter.show_bounds(location='all')
plotter.show()
# %%
# Override Shown Values Limits
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# In this example, we override the values shown along the X and Y axes with our
# own custom values. This can be useful when you wish to display different
# values along the axes without having to scale the dataset. Also, note how we
# hide the Z labels by setting ``show_zlabels=False``.
gears = examples.download_gears()
plotter = pv.Plotter()
plotter.add_mesh(gears, smooth_shading=True, split_sharp_edges=True)
plotter.show_bounds(axes_ranges=[0, 5, 0, 5, 0, 2], show_zlabels=False)
plotter.show()
print(f'Actual dataset bounds: {gears.bounds}')
# %%
# Show Bounds for Only One Dataset
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# This example shows only the bounds for a single dataset. Again we use
# ``axes_ranges`` here since in this example we want to show the size of the
# single central gear.
# separate and shift the central gear
split_gears = gears.split_bodies()
central_gear = split_gears.pop(1)
central_gear.translate([0, 60, 60], inplace=True)
# also, grab the size of the central gear's bounds
x_size, y_size, z_size = central_gear.bounds_size
plotter = pv.Plotter()
plotter.add_mesh(split_gears, smooth_shading=True, split_sharp_edges=True)
plotter.add_mesh(central_gear, smooth_shading=True, split_sharp_edges=True)
plotter.show_grid(
mesh=central_gear,
axes_ranges=[0, x_size, 0, y_size, 0, z_size],
show_xaxis=False,
bold=True,
grid=False,
)
plotter.show()
# %%
# .. tags:: plot
|