{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Shading example\n\nExample showing how to make shaded relief plots like Mathematica_ or\n`Generic Mapping Tools`_.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport numpy as np\n\nfrom matplotlib import cbook\nfrom matplotlib.colors import LightSource\n\n\ndef main():\n    # Test data\n    x, y = np.mgrid[-5:5:0.05, -5:5:0.05]\n    z = 5 * (np.sqrt(x**2 + y**2) + np.sin(x**2 + y**2))\n\n    dem = cbook.get_sample_data('jacksboro_fault_dem.npz')\n    elev = dem['elevation']\n\n    fig = compare(z, plt.colormaps[\"copper\"])\n    fig.suptitle('HSV Blending Looks Best with Smooth Surfaces', y=0.95)\n\n    fig = compare(elev, plt.colormaps[\"gist_earth\"], ve=0.05)\n    fig.suptitle('Overlay Blending Looks Best with Rough Surfaces', y=0.95)\n\n    plt.show()\n\n\ndef compare(z, cmap, ve=1):\n    # Create subplots and hide ticks\n    fig, axs = plt.subplots(ncols=2, nrows=2)\n    for ax in axs.flat:\n        ax.set(xticks=[], yticks=[])\n\n    # Illuminate the scene from the northwest\n    ls = LightSource(azdeg=315, altdeg=45)\n\n    axs[0, 0].imshow(z, cmap=cmap)\n    axs[0, 0].set(xlabel='Colormapped Data')\n\n    axs[0, 1].imshow(ls.hillshade(z, vert_exag=ve), cmap='gray')\n    axs[0, 1].set(xlabel='Illumination Intensity')\n\n    rgb = ls.shade(z, cmap=cmap, vert_exag=ve, blend_mode='hsv')\n    axs[1, 0].imshow(rgb)\n    axs[1, 0].set(xlabel='Blend Mode: \"hsv\" (default)')\n\n    rgb = ls.shade(z, cmap=cmap, vert_exag=ve, blend_mode='overlay')\n    axs[1, 1].imshow(rgb)\n    axs[1, 1].set(xlabel='Blend Mode: \"overlay\"')\n\n    return fig\n\n\nif __name__ == '__main__':\n    main()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        ".. admonition:: References\n\n   The use of the following functions, methods, classes and modules is shown\n   in this example:\n\n   - `matplotlib.colors.LightSource`\n   - `matplotlib.axes.Axes.imshow` / `matplotlib.pyplot.imshow`\n\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.14.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}