
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "tutorial/01_basic/a_lesson_basic.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_tutorial_01_basic_a_lesson_basic.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_01_basic_a_lesson_basic.py:


.. _basic_lesson:

Basic Usage Lesson
==================

This section demonstrates how to use PyVista to read and plot 3D data
using the `pyvista.examples.downloads
<https://docs.pyvista.org/api/examples/_autosummary/pyvista.examples.downloads.html>`_
module and external files.

.. GENERATED FROM PYTHON SOURCE LINES 12-20

.. code-block:: Python


    import pyvista as pv
    from pyvista import examples

    # Set the default plot theme to the "document" theme.
    # pv.set_plot_theme('document')









.. GENERATED FROM PYTHON SOURCE LINES 21-27

Using Existing Data
~~~~~~~~~~~~~~~~~~~
There are two main ways of getting data into PyVista: creating it yourself from
scratch or loading the dataset from any one of the `compatible file formats
<https://docs.pyvista.org/api/readers/index.html>`_. Since we're just starting
out, let's load a file.

.. GENERATED FROM PYTHON SOURCE LINES 27-38

.. code-block:: Python


    # If you have a dataset handy, like a surface model, point cloud, or VTK file,
    # you can use that. If you don't have something immediately available, PyVista
    # has a variety of files you can download in its `pyvista.examples.downloads
    # <https://docs.pyvista.org/api/examples/_autosummary/pyvista.examples.downloads.html>`_
    #


    dataset = examples.download_saddle_surface()
    dataset






.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">

    <table style='width: 100%;'>
    <tr><th>PolyData</th><th>Information</th></tr>
    <tr><td>N Cells</td><td>5131</td></tr>
    <tr><td>N Points</td><td>2669</td></tr>
    <tr><td>N Strips</td><td>0</td></tr>
    <tr><td>X Bounds</td><td>-2.001e+01, 2.000e+01</td></tr>
    <tr><td>Y Bounds</td><td>-6.480e-01, 4.024e+01</td></tr>
    <tr><td>Z Bounds</td><td>-6.093e-01, 1.513e+01</td></tr>
    <tr><td>N Arrays</td><td>0</td></tr>
    </table>


    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 39-41

Note how this is a :class:`pyvista.PolyData`, which is effectively a surface
dataset containing points, lines, and/or faces. We can immediately plot this with:

.. GENERATED FROM PYTHON SOURCE LINES 41-44

.. code-block:: Python


    dataset.plot()








.. tab-set::



   .. tab-item:: Static Scene



            
     .. image-sg:: /tutorial/01_basic/images/sphx_glr_a_lesson_basic_001.png
        :alt: a lesson basic
        :srcset: /tutorial/01_basic/images/sphx_glr_a_lesson_basic_001.png
        :class: sphx-glr-single-img
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /home/runner/work/pyvista-tutorial/pyvista-tutorial/doc/source/tutorial/01_basic/images/sphx_glr_a_lesson_basic_001.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 45-50

This is a fairly basic plot. You can change how its plotted by adding
parameters as ``show_edges=True`` or changing the color by setting ``color`` to
a different value. All of this is described in PyVista's API documentation in
:func:`pyvista.plot`, but for now let's take a look at another dataset. This
one is a volumetric dataset.

.. GENERATED FROM PYTHON SOURCE LINES 50-54

.. code-block:: Python


    dataset = examples.download_frog()
    dataset






.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <table style='width: 100%;'><tr><th>Header</th><th>Data Arrays</th></tr><tr><td>
    <table style='width: 100%;'>
    <tr><th>ImageData</th><th>Information</th></tr>
    <tr><td>N Cells</td><td>31594185</td></tr>
    <tr><td>N Points</td><td>31960000</td></tr>
    <tr><td>X Bounds</td><td>0.000e+00, 4.990e+02</td></tr>
    <tr><td>Y Bounds</td><td>0.000e+00, 4.690e+02</td></tr>
    <tr><td>Z Bounds</td><td>0.000e+00, 2.025e+02</td></tr>
    <tr><td>Dimensions</td><td>500, 470, 136</td></tr>
    <tr><td>Spacing</td><td>1.000e+00, 1.000e+00, 1.500e+00</td></tr>
    <tr><td>N Arrays</td><td>1</td></tr>
    </table>

    </td><td>
    <table style='width: 100%;'>
    <tr><th>Name</th><th>Field</th><th>Type</th><th>N Comp</th><th>Min</th><th>Max</th></tr>
    <tr><td><b>MetaImage</b></td><td>Points</td><td>uint8</td><td>1</td><td>0.000e+00</td><td>2.540e+02</td></tr>
    </table>

    </td></tr> </table>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 55-59

This is a :class:`pyvista.ImageData`, which is a dataset containing a uniform
set of points with consistent spacing. When we plot this dataset, we have the
option of enabling volumetric plotting, which plots individual cells based on
the content of the data associated with those cells.

.. GENERATED FROM PYTHON SOURCE LINES 59-63

.. code-block:: Python


    dataset.plot(volume=True)









.. tab-set::



   .. tab-item:: Static Scene



            
     .. image-sg:: /tutorial/01_basic/images/sphx_glr_a_lesson_basic_002.png
        :alt: a lesson basic
        :srcset: /tutorial/01_basic/images/sphx_glr_a_lesson_basic_002.png
        :class: sphx-glr-single-img
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /home/runner/work/pyvista-tutorial/pyvista-tutorial/doc/source/tutorial/01_basic/images/sphx_glr_a_lesson_basic_002.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 64-74

Read from a file
~~~~~~~~~~~~~~~~
You can read datasets directly from a file if you have access to it on your
environment. This can be one of the many file formats that VTK supports, and
many more that it doesn't as PyVista can rely on libraries like `meshio
<https://github.com/nschloe/meshio>`_.

In the following example, we load VTK's iron protein dataset `ironProt.vtk
<https://github.com/naucoin/VTKData/blob/master/Data/ironProt.vtk>`_ from a
file using :func:`pyvista.read`.

.. GENERATED FROM PYTHON SOURCE LINES 74-78

.. code-block:: Python


    dataset = pv.read("ironProt.vtk")
    dataset






.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <table style='width: 100%;'><tr><th>Header</th><th>Data Arrays</th></tr><tr><td>
    <table style='width: 100%;'>
    <tr><th>ImageData</th><th>Information</th></tr>
    <tr><td>N Cells</td><td>300763</td></tr>
    <tr><td>N Points</td><td>314432</td></tr>
    <tr><td>X Bounds</td><td>0.000e+00, 6.700e+01</td></tr>
    <tr><td>Y Bounds</td><td>0.000e+00, 6.700e+01</td></tr>
    <tr><td>Z Bounds</td><td>0.000e+00, 6.700e+01</td></tr>
    <tr><td>Dimensions</td><td>68, 68, 68</td></tr>
    <tr><td>Spacing</td><td>1.000e+00, 1.000e+00, 1.000e+00</td></tr>
    <tr><td>N Arrays</td><td>1</td></tr>
    </table>

    </td><td>
    <table style='width: 100%;'>
    <tr><th>Name</th><th>Field</th><th>Type</th><th>N Comp</th><th>Min</th><th>Max</th></tr>
    <tr><td><b>scalars</b></td><td>Points</td><td>uint8</td><td>1</td><td>0.000e+00</td><td>2.550e+02</td></tr>
    </table>

    </td></tr> </table>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 79-81

This is again a :class:`pyvista.ImageData` and we can plot it volumetrically
with:

.. GENERATED FROM PYTHON SOURCE LINES 81-84

.. code-block:: Python


    dataset.plot(volume=True)








.. tab-set::



   .. tab-item:: Static Scene



            
     .. image-sg:: /tutorial/01_basic/images/sphx_glr_a_lesson_basic_003.png
        :alt: a lesson basic
        :srcset: /tutorial/01_basic/images/sphx_glr_a_lesson_basic_003.png
        :class: sphx-glr-single-img
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /home/runner/work/pyvista-tutorial/pyvista-tutorial/doc/source/tutorial/01_basic/images/sphx_glr_a_lesson_basic_003.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 85-92

.. raw:: html

    <center>
      <a target="_blank" href="https://colab.research.google.com/github/pyvista/pyvista-tutorial/blob/gh-pages/notebooks/tutorial/01_basic/a_lesson_basic.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.793 seconds)


.. _sphx_glr_download_tutorial_01_basic_a_lesson_basic.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/01_basic/a_lesson_basic.ipynb
        :alt: Launch binder
        :width: 150 px

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: a_lesson_basic.ipynb <a_lesson_basic.ipynb>`

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

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

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

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


.. only:: html

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

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