|
| 1 | +""" |
| 2 | +Plotting Earth relief |
| 3 | +===================== |
| 4 | +
|
| 5 | +Plotting a map of Earth relief can use the data accessed by the |
| 6 | +:meth:`pygmt.datasets.load_earth_relief` method. The data can then be plotted using the |
| 7 | +:meth:`pygmt.Figure.grdimage` method. |
| 8 | +""" |
| 9 | + |
| 10 | +import pygmt |
| 11 | + |
| 12 | +######################################################################################## |
| 13 | +# Load sample Earth relief data for the entire globe at a resolution of 30 minutes. |
| 14 | +# The other available resolutions are show at :gmt-docs:`datasets/remote-data.html#global-earth-relief-grids`. |
| 15 | +grid = pygmt.datasets.load_earth_relief(resolution="30m") |
| 16 | + |
| 17 | +######################################################################################## |
| 18 | +# Create a plot |
| 19 | +# ------------- |
| 20 | +# |
| 21 | +# The :meth:`pygmt.Figure.grdimage` method takes the ``grid`` input to |
| 22 | +# create a figure. It creates and applies a color palette to the figure based upon the |
| 23 | +# z-values of the data. By default, it plots the map with the *turbo* CPT, an |
| 24 | +# equidistant cylindrical projection, and with no frame. |
| 25 | + |
| 26 | +fig = pygmt.Figure() |
| 27 | +fig.grdimage(grid=grid) |
| 28 | +fig.show() |
| 29 | + |
| 30 | +######################################################################################## |
| 31 | +# |
| 32 | +# :meth:`pygmt.Figure.grdimage` can take the optional argument ``projection`` for the |
| 33 | +# map. In the example below, the ``projection`` is set as ``"R12c"`` for 12 centimeter |
| 34 | +# figure with a Winkel Tripel projection. For a list of available projections, |
| 35 | +# see :gmt-docs:`cookbook/map-projections.html`. |
| 36 | + |
| 37 | +fig = pygmt.Figure() |
| 38 | +fig.grdimage(grid=grid, projection="R12c") |
| 39 | +fig.show() |
| 40 | + |
| 41 | +######################################################################################## |
| 42 | +# Set a color map |
| 43 | +# --------------- |
| 44 | +# |
| 45 | +# :meth:`pygmt.Figure.grdimage` takes the ``cmap`` argument to set the CPT of the |
| 46 | +# figure. Examples of common CPTs for Earth relief are shown below. |
| 47 | +# A full list of CPTs can be found at :gmt-docs:`cookbook/cpts.html`. |
| 48 | + |
| 49 | +######################################################################################## |
| 50 | +# |
| 51 | +# Using the *geo* CPT: |
| 52 | + |
| 53 | +fig = pygmt.Figure() |
| 54 | +fig.grdimage(grid=grid, projection="R12c", cmap="geo") |
| 55 | +fig.show() |
| 56 | + |
| 57 | +######################################################################################## |
| 58 | +# |
| 59 | +# Using the *relief* CPT: |
| 60 | + |
| 61 | +fig = pygmt.Figure() |
| 62 | +fig.grdimage(grid=grid, projection="R12c", cmap="relief") |
| 63 | +fig.show() |
| 64 | + |
| 65 | +######################################################################################## |
| 66 | +# Add a color bar |
| 67 | +# --------------- |
| 68 | +# |
| 69 | +# The :meth:`pygmt.Figure.colorbar` method displays the CPT and the associated Z-values |
| 70 | +# of the figure, and by default uses the same CPT set by the ``cmap`` argument |
| 71 | +# for :meth:`pygmt.Figure.grdimage`. The ``frame`` argument for |
| 72 | +# :meth:`pygmt.Figure.colorbar` can be used to set the axis intervals and labels. A |
| 73 | +# list is used to pass multiple arguments to ``frame``. In the example below, |
| 74 | +# ``"a2500"`` sets the axis interval to 2,500, ``"x+lElevation"`` sets the x-axis |
| 75 | +# label, and ``"y+lm"`` sets the y-axis label. |
| 76 | + |
| 77 | +fig = pygmt.Figure() |
| 78 | +fig.grdimage(grid=grid, projection="R12c", cmap="geo") |
| 79 | +fig.colorbar(frame=["a2500", "x+lElevation", "y+lm"]) |
| 80 | +fig.show() |
| 81 | + |
| 82 | +######################################################################################## |
| 83 | +# Create a region map |
| 84 | +# ------------------- |
| 85 | +# |
| 86 | +# In addition to providing global data, the ``region`` argument for |
| 87 | +# :meth:`pygmt.datasets.load_earth_relief` can be used to provide data for a specific |
| 88 | +# area. The ``region`` argument is required for resolutions at 5 minutes or higher, and |
| 89 | +# accepts a list (as in the example below) or a string. The geographic ranges are |
| 90 | +# passed as *x-min*/*x-max*/*y-min*/*y-max*. |
| 91 | +# |
| 92 | +# The example below uses data with a 5 minute resolution, and plots it on a |
| 93 | +# 15 centimeter figure with a Mercator projection and a CPT set to *geo*. |
| 94 | +# ``frame="a"`` is used to add a frame to the figure. |
| 95 | + |
| 96 | +grid = pygmt.datasets.load_earth_relief(resolution="05m", region=[-14, 30, 35, 60]) |
| 97 | +fig = pygmt.Figure() |
| 98 | +fig.grdimage(grid=grid, projection="M15c", frame="a", cmap="geo") |
| 99 | +fig.colorbar(frame=["a1000", "x+lElevation", "y+lm"]) |
| 100 | +fig.show() |
0 commit comments