| 1 |
""" |
| 2 |
.. _plot_over_line_example: |
| 3 |
|
| 4 |
Plot Over Line |
| 5 |
~~~~~~~~~~~~~~ |
| 6 |
|
| 7 |
Plot the values of a dataset over a line through that dataset |
| 8 |
using the :meth:`~pyvista.DataSetFilters.plot_over_line` filter. |
| 9 |
""" |
| 10 |
|
| 11 |
# sphinx_gallery_thumbnail_number = 2 |
| 12 |
import pyvista as pv |
| 13 |
from pyvista import examples |
| 14 |
|
| 15 |
# sphinx_gallery_start_ignore |
| 16 |
# white wireframe over white background does not show up in interactive plots |
| 17 |
PYVISTA_GALLERY_FORCE_STATIC_IN_DOCUMENT = True |
| 18 |
# sphinx_gallery_end_ignore |
| 19 |
|
| 20 |
# %% |
| 21 |
# Volumetric Mesh |
| 22 |
# +++++++++++++++ |
| 23 |
# |
| 24 |
# First a 3D mesh example to demonstrate |
| 25 |
mesh = examples.download_kitchen() |
| 26 |
|
| 27 |
# Make two points to construct the line between |
| 28 |
a = [mesh.bounds.x_min, mesh.bounds.y_min, mesh.bounds.z_min] |
| 29 |
b = [mesh.bounds.x_max, mesh.bounds.y_max, mesh.bounds.z_max] |
| 30 |
|
| 31 |
# Preview how this line intersects this mesh |
| 32 |
line = pv.Line(a, b) |
| 33 |
|
| 34 |
pl = pv.Plotter() |
| 35 |
pl.add_mesh(mesh, style='wireframe', color='w') |
| 36 |
pl.add_mesh(line, color='b') |
| 37 |
pl.show() |
| 38 |
|
| 39 |
# %% |
| 40 |
# Run the filter and produce a line plot |
| 41 |
mesh.plot_over_line(a, b, resolution=100) |
| 42 |
|
| 43 |
|
| 44 |
# %% |
| 45 |
# Flat Surface |
| 46 |
# ++++++++++++ |
| 47 |
# |
| 48 |
# We could also plot the values of a mesh that lies on a flat surface |
| 49 |
mesh = examples.download_st_helens() |
| 50 |
|
| 51 |
# Make two points to construct the line between |
| 52 |
a = [mesh.center[0], mesh.bounds.y_min, mesh.bounds.z_max] |
| 53 |
b = [mesh.center[0], mesh.bounds.y_max, mesh.bounds.z_max] |
| 54 |
|
| 55 |
# Preview how this line intersects this mesh |
| 56 |
line = pv.Line(a, b) |
| 57 |
|
| 58 |
pl = pv.Plotter() |
| 59 |
pl.add_mesh(mesh) |
| 60 |
pl.add_mesh(line, color='white', line_width=10) |
| 61 |
pl.add_point_labels([a, b], ['A', 'B'], font_size=48, point_color='red', text_color='red') |
| 62 |
pl.show() |
| 63 |
|
| 64 |
# %% |
| 65 |
# Run the filter and produce a line plot |
| 66 |
mesh.plot_over_line( |
| 67 |
a, |
| 68 |
b, |
| 69 |
resolution=10000, |
| 70 |
title='Elevation Profile', |
| 71 |
ylabel='Height above sea level', |
| 72 |
figsize=(10, 5), |
| 73 |
) |
| 74 |
# %% |
| 75 |
# .. tags:: plot |