Topographic Hillshading#

Download this notebook from GitHub (right-click to download).


URL: http://matplotlib.org/examples/specialty_plots/topographic_hillshading.html

Most examples work across multiple plotting backends, this example is also available for:

import holoviews as hv
from holoviews import opts
hv.extension('bokeh')

Define data#

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.cbook import get_sample_data
from matplotlib.colors import LightSource

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

dx, dy = dem['dx'], dem['dy']
dy = 111200 * dy
dx = 111200 * dx * np.cos(np.radians(dem['ymin']))

# Shade from the northwest, with the sun 45 degrees from horizontal
ls = LightSource(azdeg=315, altdeg=45)
cmap = plt.cm.gist_earth

# Vary vertical exaggeration and blend mode and plot all combinations
grid = hv.GridMatrix(kdims=['Vertical exaggeration', 'Blend mode', ])
for ve in [0.1, 1, 10]:
    # Show the hillshade intensity image in the first row
    grid['None', ve] = hv.Image(ls.hillshade(z, vert_exag=ve, dx=dx, dy=dy))
    # Place hillshaded plots with different blend modes in the rest of the rows
    for mode in ['hsv', 'overlay', 'soft']:
        rgb = ls.shade(z, cmap=cmap, blend_mode=mode,
                       vert_exag=ve, dx=dx, dy=dy)
        grid[mode, ve] = hv.RGB(rgb)

Plot#

grid.opts(
    opts.GridMatrix(xaxis='bottom', yaxis='left', shared_xaxis=False, shared_yaxis=False),
    opts.Image(cmap='gray'))
This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.

Download this notebook from GitHub (right-click to download).