Topographic hillshading


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

In [1]:
import numpy as np
import holoviews as hv
%output fig='svg'

Define data

In [2]:
import numpy as np
import holoviews as hv
import matplotlib.pyplot as plt
from matplotlib.cbook import get_sample_data
from matplotlib.colors import LightSource

dem = np.load(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 =

# 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)
opts = {'GridMatrix': {'plot': dict(xaxis='bottom', shared_xaxis=False, shared_yaxis=False,
                                    yaxis='left', bgcolor='white')},
       'Image': {'style': dict(cmap='gray')}}


In [3]:

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