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

.. only:: html

    .. meta::
        :keywords: codex

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

        :ref:`Go to the end <sphx_glr_download_gallery_images_contours_and_fields_shading_example.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_images_contours_and_fields_shading_example.py:


===============
Shading example
===============

Example showing how to make shaded relief plots like Mathematica_ or
`Generic Mapping Tools`_.

.. _Mathematica: http://reference.wolfram.com/mathematica/ref/ReliefPlot.html
.. _Generic Mapping Tools: https://www.generic-mapping-tools.org/

.. GENERATED FROM PYTHON SOURCE LINES 12-66

.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    from matplotlib import cbook
    from matplotlib.colors import LightSource


    def main():
        # Test data
        x, y = np.mgrid[-5:5:0.05, -5:5:0.05]
        z = 5 * (np.sqrt(x**2 + y**2) + np.sin(x**2 + y**2))

        dem = cbook.get_sample_data('jacksboro_fault_dem.npz')
        elev = dem['elevation']

        fig = compare(z, plt.cm.copper)
        fig.suptitle('HSV Blending Looks Best with Smooth Surfaces', y=0.95)

        fig = compare(elev, plt.cm.gist_earth, ve=0.05)
        fig.suptitle('Overlay Blending Looks Best with Rough Surfaces', y=0.95)

        plt.show()


    def compare(z, cmap, ve=1):
        # Create subplots and hide ticks
        fig, axs = plt.subplots(ncols=2, nrows=2)
        for ax in axs.flat:
            ax.set(xticks=[], yticks=[])

        # Illuminate the scene from the northwest
        ls = LightSource(azdeg=315, altdeg=45)

        axs[0, 0].imshow(z, cmap=cmap)
        axs[0, 0].set(xlabel='Colormapped Data')

        axs[0, 1].imshow(ls.hillshade(z, vert_exag=ve), cmap='gray')
        axs[0, 1].set(xlabel='Illumination Intensity')

        rgb = ls.shade(z, cmap=cmap, vert_exag=ve, blend_mode='hsv')
        axs[1, 0].imshow(rgb)
        axs[1, 0].set(xlabel='Blend Mode: "hsv" (default)')

        rgb = ls.shade(z, cmap=cmap, vert_exag=ve, blend_mode='overlay')
        axs[1, 1].imshow(rgb)
        axs[1, 1].set(xlabel='Blend Mode: "overlay"')

        return fig


    if __name__ == '__main__':
        main()




.. rst-class:: sphx-glr-horizontal


    *

      .. image-sg:: /gallery/images_contours_and_fields/images/sphx_glr_shading_example_001.png
         :alt: HSV Blending Looks Best with Smooth Surfaces
         :srcset: /gallery/images_contours_and_fields/images/sphx_glr_shading_example_001.png, /gallery/images_contours_and_fields/images/sphx_glr_shading_example_001_2_00x.png 2.00x
         :class: sphx-glr-multi-img

    *

      .. image-sg:: /gallery/images_contours_and_fields/images/sphx_glr_shading_example_002.png
         :alt: Overlay Blending Looks Best with Rough Surfaces
         :srcset: /gallery/images_contours_and_fields/images/sphx_glr_shading_example_002.png, /gallery/images_contours_and_fields/images/sphx_glr_shading_example_002_2_00x.png 2.00x
         :class: sphx-glr-multi-img





.. GENERATED FROM PYTHON SOURCE LINES 67-74

.. admonition:: References

   The use of the following functions, methods, classes and modules is shown
   in this example:

   - `matplotlib.colors.LightSource`
   - `matplotlib.axes.Axes.imshow` / `matplotlib.pyplot.imshow`


.. _sphx_glr_download_gallery_images_contours_and_fields_shading_example.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

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

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

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

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

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

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


.. only:: html

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

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