Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ed5cd76

Browse files
committed
Updated shading example to show new styles and added exmaple DEM from SRTM data
1 parent a1af495 commit ed5cd76

2 files changed

Lines changed: 40 additions & 19 deletions

File tree

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,49 @@
11
import numpy as np
22
import matplotlib.pyplot as plt
33
from matplotlib.colors import LightSource
4+
from matplotlib import cbook
45

5-
# example showing how to make shaded relief plots
6+
# Example showing how to make shaded relief plots
67
# like Mathematica
78
# (http://reference.wolfram.com/mathematica/ref/ReliefPlot.html)
89
# or Generic Mapping Tools
910
# (http://gmt.soest.hawaii.edu/gmt/doc/gmt/html/GMT_Docs/node145.html)
1011

11-
# test data
12-
X,Y=np.mgrid[-5:5:0.05,-5:5:0.05]
13-
Z=np.sqrt(X**2+Y**2)+np.sin(X**2+Y**2)
14-
# create light source object.
15-
ls = LightSource(azdeg=0,altdeg=65)
16-
# shade data, creating an rgb array.
17-
rgb = ls.shade(Z,plt.cm.copper)
18-
# plot un-shaded and shaded images.
19-
plt.figure(figsize=(12,5))
20-
plt.subplot(121)
21-
plt.imshow(Z,cmap=plt.cm.copper)
22-
plt.title('imshow')
23-
plt.xticks([]); plt.yticks([])
24-
plt.subplot(122)
25-
plt.imshow(rgb)
26-
plt.title('imshow with shading')
27-
plt.xticks([]); plt.yticks([])
28-
plt.show()
12+
def main():
13+
# Test data
14+
x, y = np.mgrid[-5:5:0.05, -5:5:0.05]
15+
z = 5 * (np.sqrt(x**2 + y**2) + np.sin(x**2 + y**2))
16+
fig = compare(z, plt.cm.copper)
17+
fig.suptitle('HSV Blending Looks Best with Smooth Surfaces', y=0.95)
18+
19+
dem = np.load(cbook.get_sample_data('jacksboro_fault_dem.npz'))
20+
fig = compare(dem['elevation'], plt.cm.gist_earth, ve=0.05)
21+
fig.suptitle('Overlay Blending Looks Best with Rough Surfaces', y=0.95)
22+
23+
plt.show()
24+
25+
def compare(z, cmap, ve=1):
26+
# Create subplots and hide ticks
27+
fig, axes = plt.subplots(ncols=2, nrows=2)
28+
for ax in axes.flat:
29+
ax.set(xticks=[], yticks=[])
30+
31+
# Illuminate the scene from the northwest
32+
ls = LightSource(azdeg=315, altdeg=45)
33+
34+
axes[0,0].imshow(z, cmap=cmap)
35+
axes[0,0].set(xlabel='Colormapped Data')
36+
37+
axes[0,1].imshow(ls.hillshade(z, vert_exag=ve), cmap='gray')
38+
axes[0,1].set(xlabel='Illumination Intensity')
39+
40+
axes[1,0].imshow(ls.shade(z, cmap=cmap, vert_exag=ve, blend_mode='hsv'))
41+
axes[1,0].set(xlabel='Blend Mode: "hsv" (default)')
42+
43+
axes[1,1].imshow(ls.shade(z, cmap=cmap, vert_exag=ve, blend_mode='overlay'))
44+
axes[1,1].set(xlabel='Blend Mode: "overlay"')
45+
46+
return fig
47+
48+
if __name__ == '__main__':
49+
main()
170 KB
Binary file not shown.

0 commit comments

Comments
 (0)