|
| 1 | +""" |
| 2 | +Creating a 3D perspective image |
| 3 | +=============================== |
| 4 | +
|
| 5 | +Create 3-D perspective image or surface mesh from a grid |
| 6 | +using :meth:`pygmt.Figure.grdview`. |
| 7 | +""" |
| 8 | + |
| 9 | +import pygmt |
| 10 | + |
| 11 | +# Load sample earth relief data |
| 12 | +grid = pygmt.datasets.load_earth_relief(resolution="05m", region=[-108, -103, 35, 40]) |
| 13 | + |
| 14 | +######################################################################################## |
| 15 | +# The :meth:`pygmt.Figure.grdview` method takes the ``grid`` input. |
| 16 | +# The ``perspective`` argument changes the azimuth and elevation of the viewpoint; the |
| 17 | +# default is [180, 90], which is looking directly down on the figure and north is "up". |
| 18 | +# The ``zsize`` argument sets how tall the three-dimensional portion appears. |
| 19 | +# |
| 20 | +# The default grid surface type is *mesh plot*. |
| 21 | + |
| 22 | +fig = pygmt.Figure() |
| 23 | +fig.grdview( |
| 24 | + grid=grid, |
| 25 | + # Sets the view azimuth as 130 degrees, and the view elevation as 30 degrees |
| 26 | + perspective=[130, 30], |
| 27 | + # Sets the x- and y-axis labels, and annotates the west, south, and east axes |
| 28 | + frame=["xa", "ya", "WSnE"], |
| 29 | + # Sets a Mercator projection on a 15-centimeter figure |
| 30 | + projection="M15c", |
| 31 | + # Sets the height of the three-dimensional relief at 1.5 centimeters |
| 32 | + zsize="1.5c", |
| 33 | +) |
| 34 | +fig.show() |
| 35 | + |
| 36 | +######################################################################################## |
| 37 | +# The grid surface type can be set with the ``surftype`` parameter. |
| 38 | + |
| 39 | +fig = pygmt.Figure() |
| 40 | +fig.grdview( |
| 41 | + grid=grid, |
| 42 | + perspective=[130, 30], |
| 43 | + frame=["xa", "ya", "WSnE"], |
| 44 | + projection="M15c", |
| 45 | + zsize="1.5c", |
| 46 | + # Set the surftype to "surface" |
| 47 | + surftype="s", |
| 48 | +) |
| 49 | +fig.show() |
| 50 | + |
| 51 | +######################################################################################## |
| 52 | +# The default CPT is *turbo* and can be customized with the ``cmap`` parameter. |
| 53 | + |
| 54 | +fig = pygmt.Figure() |
| 55 | +fig.grdview( |
| 56 | + grid=grid, |
| 57 | + perspective=[130, 30], |
| 58 | + frame=["xa", "yaf", "WSnE"], |
| 59 | + projection="M15c", |
| 60 | + zsize="1.5c", |
| 61 | + surftype="s", |
| 62 | + # Set the CPT to "geo" |
| 63 | + cmap="geo", |
| 64 | +) |
| 65 | +fig.show() |
| 66 | + |
| 67 | +######################################################################################## |
| 68 | +# The ``plane`` argument sets the elevation and color of a plane that provides a fill |
| 69 | +# below the surface relief. |
| 70 | + |
| 71 | +fig = pygmt.Figure() |
| 72 | +fig.grdview( |
| 73 | + grid=grid, |
| 74 | + perspective=[130, 30], |
| 75 | + frame=["xa", "yaf", "WSnE"], |
| 76 | + projection="M15c", |
| 77 | + zsize="1.5c", |
| 78 | + surftype="s", |
| 79 | + cmap="geo", |
| 80 | + # Set the plane elevation to 1,000 meters and make the fill "gray" |
| 81 | + plane="1000+ggray", |
| 82 | +) |
| 83 | +fig.show() |
| 84 | + |
| 85 | +######################################################################################## |
| 86 | +# The ``perspective`` azimuth can be changed to set the direction that is "up" |
| 87 | +# in the figure. |
| 88 | + |
| 89 | +fig = pygmt.Figure() |
| 90 | +fig.grdview( |
| 91 | + grid=grid, |
| 92 | + # Set the azimuth to -130 (230) degrees and the elevation to 30 degrees |
| 93 | + perspective=[-130, 30], |
| 94 | + frame=["xa", "yaf", "WSnE"], |
| 95 | + projection="M15c", |
| 96 | + zsize="1.5c", |
| 97 | + surftype="s", |
| 98 | + cmap="geo", |
| 99 | + plane="1000+ggrey", |
| 100 | +) |
| 101 | +fig.show() |
| 102 | + |
| 103 | +######################################################################################## |
| 104 | +# The ``contourpen`` parameter sets the pen used to draw contour lines on the surface. |
| 105 | + |
| 106 | +fig = pygmt.Figure() |
| 107 | +fig.grdview( |
| 108 | + grid=grid, |
| 109 | + perspective=[-130, 30], |
| 110 | + frame=["xaf", "yaf", "WSnE"], |
| 111 | + projection="M15c", |
| 112 | + zsize="1.5c", |
| 113 | + surftype="s", |
| 114 | + cmap="geo", |
| 115 | + plane="1000+ggrey", |
| 116 | + # Set the contour pen thickness to "0.5p" |
| 117 | + contourpen="0.5p", |
| 118 | +) |
| 119 | +fig.show() |
| 120 | + |
| 121 | +######################################################################################## |
| 122 | +# :meth:`pygmt.Figure.colorbar` can be used to add a color bar to the figure. The |
| 123 | +# ``cmap`` argument does not need to be passed again. To keep the color bar's alignment |
| 124 | +# similar to the figure, use **True** as the ``perspective`` argument. |
| 125 | + |
| 126 | +fig = pygmt.Figure() |
| 127 | +fig.grdview( |
| 128 | + grid=grid, |
| 129 | + perspective=[-130, 30], |
| 130 | + frame=["xaf", "yaf", "WSnE"], |
| 131 | + projection="M15c", |
| 132 | + zsize="1.5c", |
| 133 | + surftype="s", |
| 134 | + cmap="geo", |
| 135 | + plane="1000+ggrey", |
| 136 | + contourpen="0.1p", |
| 137 | +) |
| 138 | +fig.colorbar(perspective=True, frame=["a500", "x+lElevation", "y+lm"]) |
| 139 | +fig.show() |
0 commit comments