
.. 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 <sphx_glr_download_tutorial_03_figures_a_lesson_figures.py>`
        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 5-11

.. code-block:: Python


    import pyvista as pv
    from pyvista import examples

    mesh = pv.Wavelet()








.. GENERATED FROM PYTHON SOURCE LINES 12-16

``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 16-21

.. code-block:: Python


    pl = pv.Plotter()
    pl.add_mesh(mesh)
    pl.show()








.. tab-set::



   .. tab-item:: Static Scene



            
     .. 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
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /home/runner/work/pyvista-tutorial/pyvista-tutorial/doc/source/tutorial/03_figures/images/sphx_glr_a_lesson_figures_001.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 22-23

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 23-28

.. code-block:: Python


    pl = pv.Plotter()
    pl.add_mesh(mesh, cmap="coolwarm")
    pl.show()








.. tab-set::



   .. tab-item:: Static Scene



            
     .. 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
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /home/runner/work/pyvista-tutorial/pyvista-tutorial/doc/source/tutorial/03_figures/images/sphx_glr_a_lesson_figures_002.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 29-30

Or show the edges of the mesh with ``show_edges``:

.. GENERATED FROM PYTHON SOURCE LINES 30-35

.. code-block:: Python


    pl = pv.Plotter()
    pl.add_mesh(mesh, show_edges=True)
    pl.show()








.. tab-set::



   .. tab-item:: Static Scene



            
     .. 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
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /home/runner/work/pyvista-tutorial/pyvista-tutorial/doc/source/tutorial/03_figures/images/sphx_glr_a_lesson_figures_003.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 36-37

Or adjust the opacity to be a scalar value or linear transfer function via the ``opacity`` argument:

.. GENERATED FROM PYTHON SOURCE LINES 37-44

.. code-block:: Python


    mesh = examples.download_st_helens().warp_by_scalar()

    pl = pv.Plotter()
    pl.add_mesh(mesh, cmap="terrain", opacity="linear")
    pl.show()








.. tab-set::



   .. tab-item:: Static Scene



            
     .. 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
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /home/runner/work/pyvista-tutorial/pyvista-tutorial/doc/source/tutorial/03_figures/images/sphx_glr_a_lesson_figures_004.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 45-48

Take a look at all of the options for `add_mesh <https://docs.pyvista.org/api/plotting/_autosummary/pyvista.Plotter.add_mesh.html>`_.

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 48-74

.. 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)]

    pl = pv.Plotter(window_size=[1000, 1000])
    for _ind, solid in enumerate(solids):
        pl.add_mesh(solid, color="silver", specular=1.0, specular_power=10)
    pl.view_vector((5.0, 2, 3))
    pl.add_floor("-z", lighting=True, color="tan", pad=1.0)
    pl.enable_shadows()
    pl.show()








.. tab-set::



   .. tab-item:: Static Scene



            
     .. 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
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /home/runner/work/pyvista-tutorial/pyvista-tutorial/doc/source/tutorial/03_figures/images/sphx_glr_a_lesson_figures_005.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 75-79

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 79-89

.. code-block:: Python

    pl = pv.Plotter(shape=(1, 2))

    pl.subplot(0, 0)
    pl.add_mesh(pv.Sphere())

    pl.subplot(0, 1)
    pl.add_mesh(pv.Cube())

    pl.show()








.. tab-set::



   .. tab-item:: Static Scene



            
     .. 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
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /home/runner/work/pyvista-tutorial/pyvista-tutorial/doc/source/tutorial/03_figures/images/sphx_glr_a_lesson_figures_006.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 90-95

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 95-110

.. code-block:: Python

    mesh = pv.Wavelet()
    cntr = mesh.contour()
    slices = mesh.slice_orthogonal()

    pl = pv.Plotter(shape=(1, 2))

    pl.add_mesh(cntr)

    pl.subplot(0, 1)
    pl.add_mesh(slices)

    pl.link_views()
    pl.view_isometric()
    pl.show()








.. tab-set::



   .. tab-item:: Static Scene



            
     .. 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
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /home/runner/work/pyvista-tutorial/pyvista-tutorial/doc/source/tutorial/03_figures/images/sphx_glr_a_lesson_figures_007.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 111-115

Axes and Bounds
+++++++++++++++

Axes can be added to the scene with :func:`pyvista.Plotter.show_axes`

.. GENERATED FROM PYTHON SOURCE LINES 115-124

.. code-block:: Python



    mesh = examples.load_random_hills()

    pl = pv.Plotter()
    pl.add_mesh(mesh)
    pl.show_axes()
    pl.show()








.. tab-set::



   .. tab-item:: Static Scene



            
     .. 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
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /home/runner/work/pyvista-tutorial/pyvista-tutorial/doc/source/tutorial/03_figures/images/sphx_glr_a_lesson_figures_008.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 125-130

And bounds similarly with :func:`pyvista.Plotter.show_bounds`

.. tip::

    See `Plotting Bounds <https://docs.pyvista.org/examples/02-plot/bounds.html>`_ for more details.

.. GENERATED FROM PYTHON SOURCE LINES 130-138

.. code-block:: Python



    pl = pv.Plotter()
    pl.add_mesh(mesh)
    pl.show_axes()
    pl.show_bounds()
    pl.show()








.. tab-set::



   .. tab-item:: Static Scene



            
     .. 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
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /home/runner/work/pyvista-tutorial/pyvista-tutorial/doc/source/tutorial/03_figures/images/sphx_glr_a_lesson_figures_009.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 139-146

.. raw:: html

    <center>
      <a target="_blank" href="https://colab.research.google.com/github/pyvista/pyvista-tutorial/blob/gh-pages/notebooks/tutorial/03_figures/a_lesson_figures.ipynb">
        <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/ width="150px">
      </a>
    </center>


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 5.556 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 <a_lesson_figures.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: a_lesson_figures.py <a_lesson_figures.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: a_lesson_figures.zip <a_lesson_figures.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
