地形山体阴影

在“山体阴影”图上展示不同混合模式和垂直夸大的视觉效果。

请注意,“叠加”和“柔和”混合模式适用于复杂曲面,例如此示例,而默认的“hsv”混合模式最适用于光滑曲面,例如许多数学函数。

在大多数情况下,山体阴影纯粹用于视觉目的,可以安全地忽略dx / dy。 在这种情况下,您可以通过反复试验调整vert_exag(垂直夸大)以获得所需的视觉效果。 但是,此示例演示了如何使用dx和dy kwargs来确保vert_exag参数是真正的垂直夸大。

地形山体阴影示例

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from matplotlib.cbook import get_sample_data
  4. from matplotlib.colors import LightSource
  5. with np.load(get_sample_data('jacksboro_fault_dem.npz')) as dem:
  6. z = dem['elevation']
  7. #-- Optional dx and dy for accurate vertical exaggeration ----------------
  8. # If you need topographically accurate vertical exaggeration, or you don't
  9. # want to guess at what *vert_exag* should be, you'll need to specify the
  10. # cellsize of the grid (i.e. the *dx* and *dy* parameters). Otherwise, any
  11. # *vert_exag* value you specify will be relative to the grid spacing of
  12. # your input data (in other words, *dx* and *dy* default to 1.0, and
  13. # *vert_exag* is calculated relative to those parameters). Similarly, *dx*
  14. # and *dy* are assumed to be in the same units as your input z-values.
  15. # Therefore, we'll need to convert the given dx and dy from decimal degrees
  16. # to meters.
  17. dx, dy = dem['dx'], dem['dy']
  18. dy = 111200 * dy
  19. dx = 111200 * dx * np.cos(np.radians(dem['ymin']))
  20. #-------------------------------------------------------------------------
  21. # Shade from the northwest, with the sun 45 degrees from horizontal
  22. ls = LightSource(azdeg=315, altdeg=45)
  23. cmap = plt.cm.gist_earth
  24. fig, axes = plt.subplots(nrows=4, ncols=3, figsize=(8, 9))
  25. plt.setp(axes.flat, xticks=[], yticks=[])
  26. # Vary vertical exaggeration and blend mode and plot all combinations
  27. for col, ve in zip(axes.T, [0.1, 1, 10]):
  28. # Show the hillshade intensity image in the first row
  29. col[0].imshow(ls.hillshade(z, vert_exag=ve, dx=dx, dy=dy), cmap='gray')
  30. # Place hillshaded plots with different blend modes in the rest of the rows
  31. for ax, mode in zip(col[1:], ['hsv', 'overlay', 'soft']):
  32. rgb = ls.shade(z, cmap=cmap, blend_mode=mode,
  33. vert_exag=ve, dx=dx, dy=dy)
  34. ax.imshow(rgb)
  35. # Label rows and columns
  36. for ax, ve in zip(axes[0], [0.1, 1, 10]):
  37. ax.set_title('{0}'.format(ve), size=18)
  38. for ax, mode in zip(axes[:, 0], ['Hillshade', 'hsv', 'overlay', 'soft']):
  39. ax.set_ylabel(mode, size=18)
  40. # Group labels...
  41. axes[0, 1].annotate('Vertical Exaggeration', (0.5, 1), xytext=(0, 30),
  42. textcoords='offset points', xycoords='axes fraction',
  43. ha='center', va='bottom', size=20)
  44. axes[2, 0].annotate('Blend Mode', (0, 0.5), xytext=(-30, 0),
  45. textcoords='offset points', xycoords='axes fraction',
  46. ha='right', va='center', size=20, rotation=90)
  47. fig.subplots_adjust(bottom=0.05, right=0.95)
  48. plt.show()

下载这个示例