.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorial/04_filters/exercises/e_glyphs.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorial_04_filters_exercises_e_glyphs.py: Plotting Glyphs (Vectors or PolyData) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Use vectors in a dataset to plot and orient glyphs/geometric objects. .. GENERATED FROM PYTHON SOURCE LINES 7-12 .. code-block:: Python import numpy as np import pyvista as pv from pyvista import examples .. GENERATED FROM PYTHON SOURCE LINES 13-14 Example dataset with normals .. GENERATED FROM PYTHON SOURCE LINES 14-16 .. code-block:: Python mesh = examples.load_random_hills() .. GENERATED FROM PYTHON SOURCE LINES 17-18 Glyphying can be done via the :func:`pyvista.DataSetFilters.glyph` filter .. GENERATED FROM PYTHON SOURCE LINES 18-20 .. code-block:: Python help(mesh.glyph) .. GENERATED FROM PYTHON SOURCE LINES 21-27 Sometimes you might not want glyphs for every node in the input dataset. In this case, you can choose to build glyphs for a subset of the input dataset by using a merging tolerance. Here we specify a merging tolerance of five percent which equates to five percent of the bounding box's length. create a subset of arrows using the glyph filter .. GENERATED FROM PYTHON SOURCE LINES 27-30 .. code-block:: Python arrows = ... .. GENERATED FROM PYTHON SOURCE LINES 31-36 .. code-block:: Python p = pv.Plotter() p.add_mesh(arrows, color="black") p.add_mesh(mesh, scalars="Elevation", cmap="terrain", smooth_shading=True) p.show() .. GENERATED FROM PYTHON SOURCE LINES 37-39 A common approach is to load vectors directly to the mesh object and then access the :attr:`pyvista.DataSet.arrows` property to produce glyphs. .. GENERATED FROM PYTHON SOURCE LINES 39-53 .. code-block:: Python sphere = pv.Sphere(radius=3.14) # make cool swirly pattern vectors = np.vstack( ( np.sin(sphere.points[:, 0]), np.cos(sphere.points[:, 1]), np.cos(sphere.points[:, 2]), ) ).T vectors .. GENERATED FROM PYTHON SOURCE LINES 54-62 .. code-block:: Python # add and scale sphere["vectors"] = vectors * 0.3 sphere.set_active_vectors("vectors") # plot just the arrows sphere.arrows.plot() .. GENERATED FROM PYTHON SOURCE LINES 63-64 Plot the arrows and the sphere. .. GENERATED FROM PYTHON SOURCE LINES 64-69 .. code-block:: Python p = pv.Plotter() p.add_mesh(sphere.arrows, lighting=False, scalar_bar_args={'title': "Vector Magnitude"}) p.add_mesh(sphere, color="grey", ambient=0.6, opacity=0.5, show_edges=False) p.show() .. GENERATED FROM PYTHON SOURCE LINES 70-77 .. raw:: html
Open In Colab
.. _sphx_glr_download_tutorial_04_filters_exercises_e_glyphs.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/pyvista/pyvista-tutorial/gh-pages?urlpath=lab/tree/notebooks/tutorial/04_filters/exercises/e_glyphs.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: e_glyphs.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: e_glyphs.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_