.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorial/03_figures/a_lesson_figures.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_03_figures_a_lesson_figures.py: Lesson Overview ~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 6-12 .. code-block:: Python import pyvista as pv from pyvista import examples mesh = pv.Wavelet() .. GENERATED FROM PYTHON SOURCE LINES 13-17 ``add_mesh`` ++++++++++++++ When plotting, users must first create a :class:`pyvista.Plotter` instance (much like a Matplotlib figure). Then data are added to the plotter instance through the :func:`pyvista.Plotter.add_mesh` method. This workflow typically looks like: .. GENERATED FROM PYTHON SOURCE LINES 17-22 .. code-block:: Python p = pv.Plotter() p.add_mesh(mesh) p.show() .. image-sg:: /tutorial/03_figures/images/sphx_glr_a_lesson_figures_001.png :alt: a lesson figures :srcset: /tutorial/03_figures/images/sphx_glr_a_lesson_figures_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 23-24 You can customize how that mesh is displayed through the parameters of the :func:`pyvista.Plotter.add_mesh` method. For example, we can change the colormap via the ``cmap`` argument: .. GENERATED FROM PYTHON SOURCE LINES 24-29 .. code-block:: Python p = pv.Plotter() p.add_mesh(mesh, cmap='coolwarm') p.show() .. image-sg:: /tutorial/03_figures/images/sphx_glr_a_lesson_figures_002.png :alt: a lesson figures :srcset: /tutorial/03_figures/images/sphx_glr_a_lesson_figures_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 30-31 Or show the edges of the mesh with ``show_edges``: .. GENERATED FROM PYTHON SOURCE LINES 31-36 .. code-block:: Python p = pv.Plotter() p.add_mesh(mesh, show_edges=True) p.show() .. image-sg:: /tutorial/03_figures/images/sphx_glr_a_lesson_figures_003.png :alt: a lesson figures :srcset: /tutorial/03_figures/images/sphx_glr_a_lesson_figures_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 37-38 Or adjust the opacity to be a scalar value or linear transfer function via the ``opacity`` argument: .. GENERATED FROM PYTHON SOURCE LINES 38-45 .. code-block:: Python mesh = examples.download_st_helens().warp_by_scalar() p = pv.Plotter() p.add_mesh(mesh, cmap='terrain', opacity="linear") p.show() .. image-sg:: /tutorial/03_figures/images/sphx_glr_a_lesson_figures_004.png :alt: a lesson figures :srcset: /tutorial/03_figures/images/sphx_glr_a_lesson_figures_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 46-49 Take a look at all of the options for `add_mesh `_. The ``add_mesh`` method can be called over and over to add different data to the same ``Plotter`` scene. For example, we can create many different mesh objects and plot them together: .. GENERATED FROM PYTHON SOURCE LINES 49-75 .. code-block:: Python kinds = [ 'tetrahedron', 'cube', 'octahedron', 'dodecahedron', 'icosahedron', ] centers = [ (0, 1, 0), (0, 0, 0), (0, 2, 0), (-1, 0, 0), (-1, 2, 0), ] solids = [pv.PlatonicSolid(kind, radius=0.4, center=center) for kind, center in zip(kinds, centers)] p = pv.Plotter(window_size=[1000, 1000]) for ind, solid in enumerate(solids): p.add_mesh(solid, color='silver', specular=1.0, specular_power=10) p.view_vector((5.0, 2, 3)) p.add_floor('-z', lighting=True, color='tan', pad=1.0) p.enable_shadows() p.show() .. image-sg:: /tutorial/03_figures/images/sphx_glr_a_lesson_figures_005.png :alt: a lesson figures :srcset: /tutorial/03_figures/images/sphx_glr_a_lesson_figures_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 76-80 Subplotting +++++++++++ Creating side-by-side comparisons of datasets is easy with PyVista's subplotting API. Get started by specifying the shape of the :class:`pyvista.Plotter` object then registering the active subplot by the :func:`pyvista.Plotter.subplot` method much like how you subplot with Matplotlib's API. .. GENERATED FROM PYTHON SOURCE LINES 80-90 .. code-block:: Python p = pv.Plotter(shape=(1, 2)) p.subplot(0, 0) p.add_mesh(pv.Sphere()) p.subplot(0, 1) p.add_mesh(pv.Cube()) p.show() .. image-sg:: /tutorial/03_figures/images/sphx_glr_a_lesson_figures_006.png :alt: a lesson figures :srcset: /tutorial/03_figures/images/sphx_glr_a_lesson_figures_006.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 91-96 Below is an example of side-by-side comparisons of the contours and slices of a single dataset. .. tip:: You can link the cameras of both views with the :func:`pyvista.Plotter.link_views` method .. GENERATED FROM PYTHON SOURCE LINES 96-111 .. code-block:: Python mesh = pv.Wavelet() cntr = mesh.contour() slices = mesh.slice_orthogonal() p = pv.Plotter(shape=(1, 2)) p.add_mesh(cntr) p.subplot(0, 1) p.add_mesh(slices) p.link_views() p.view_isometric() p.show() .. image-sg:: /tutorial/03_figures/images/sphx_glr_a_lesson_figures_007.png :alt: a lesson figures :srcset: /tutorial/03_figures/images/sphx_glr_a_lesson_figures_007.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 112-116 Axes and Bounds +++++++++++++++ Axes can be added to the scene with :func:`pyvista.Plotter.show_axes` .. GENERATED FROM PYTHON SOURCE LINES 116-125 .. code-block:: Python mesh = examples.load_random_hills() p = pv.Plotter() p.add_mesh(mesh) p.show_axes() p.show() .. image-sg:: /tutorial/03_figures/images/sphx_glr_a_lesson_figures_008.png :alt: a lesson figures :srcset: /tutorial/03_figures/images/sphx_glr_a_lesson_figures_008.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 126-131 And bounds similarly with :func:`pyvista.Plotter.show_bounds` .. tip:: See `Plotting Bounds `_ for more details. .. GENERATED FROM PYTHON SOURCE LINES 131-139 .. code-block:: Python p = pv.Plotter() p.add_mesh(mesh) p.show_axes() p.show_bounds() p.show() .. image-sg:: /tutorial/03_figures/images/sphx_glr_a_lesson_figures_009.png :alt: a lesson figures :srcset: /tutorial/03_figures/images/sphx_glr_a_lesson_figures_009.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 140-147 .. raw:: html
Open In Colab
.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.044 seconds) .. _sphx_glr_download_tutorial_03_figures_a_lesson_figures.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/03_figures/a_lesson_figures.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: a_lesson_figures.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: a_lesson_figures.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_