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