| 1 |
""" |
| 2 |
.. _vector_component_example: |
| 3 |
|
| 4 |
Plot Vector Component |
| 5 |
~~~~~~~~~~~~~~~~~~~~~ |
| 6 |
|
| 7 |
Plot a single component of a vector as a scalar array. |
| 8 |
|
| 9 |
We can plot individual components of multi-component arrays with the |
| 10 |
``component`` argument of the :meth:`~pyvista.Plotter.add_mesh` method. |
| 11 |
""" |
| 12 |
|
| 13 |
import pyvista as pv |
| 14 |
from pyvista import examples |
| 15 |
|
| 16 |
# sphinx_gallery_start_ignore |
| 17 |
# labels are not supported in vtk-js |
| 18 |
PYVISTA_GALLERY_FORCE_STATIC_IN_DOCUMENT = True |
| 19 |
# sphinx_gallery_end_ignore |
| 20 |
|
| 21 |
|
| 22 |
# %% |
| 23 |
# Download an example notched beam stress |
| 24 |
mesh = examples.download_notch_displacement() |
| 25 |
|
| 26 |
|
| 27 |
# %% |
| 28 |
# The default behavior with no component specified is to use the |
| 29 |
# vector magnitude. We can access each component by specifying the |
| 30 |
# component argument. |
| 31 |
|
| 32 |
dargs = dict( |
| 33 |
scalars='Nodal Displacement', |
| 34 |
cmap='jet', |
| 35 |
show_scalar_bar=False, |
| 36 |
) |
| 37 |
|
| 38 |
pl = pv.Plotter(shape=(2, 2)) |
| 39 |
pl.subplot(0, 0) |
| 40 |
pl.add_mesh(mesh, **dargs) |
| 41 |
pl.add_text('Normalized Displacement', color='k') |
| 42 |
pl.subplot(0, 1) |
| 43 |
pl.add_mesh(mesh.copy(), component=0, **dargs) |
| 44 |
pl.add_text('X Displacement', color='k') |
| 45 |
pl.subplot(1, 0) |
| 46 |
pl.add_mesh(mesh.copy(), component=1, **dargs) |
| 47 |
pl.add_text('Y Displacement', color='k') |
| 48 |
pl.subplot(1, 1) |
| 49 |
pl.add_mesh(mesh.copy(), component=2, **dargs) |
| 50 |
pl.add_text('Z Displacement', color='k') |
| 51 |
pl.link_views() |
| 52 |
pl.camera_position = 'iso' |
| 53 |
pl.background_color = 'white' |
| 54 |
pl.show() |
| 55 |
# %% |
| 56 |
# .. tags:: plot |