|
2 | 2 | Cross-section along a transect
|
3 | 3 | ==============================
|
4 | 4 |
|
5 |
| -:func:`pygmt.project` and :func:`pygmt.grdtrack` can be used to focus on |
6 |
| -a quantity and its variation along a desired survey line. |
7 |
| -In this example, the elevation is extracted from a grid provided via |
8 |
| -:func:`pygmt.datasets.load_earth_relief`. |
9 |
| -The figure consists of two parts, a map of the elevation in the study |
10 |
| -area showing the survey line and a Cartesian plot showing the elevation |
11 |
| -along the survey line. |
| 5 | +:func:`pygmt.project` and :func:`pygmt.grdtrack` can be used to focus on a quantity and |
| 6 | +its variation along a desired survey line. In this example, the elevation is extracted |
| 7 | +from a grid provided via :func:`pygmt.datasets.load_earth_relief`. The figure consists |
| 8 | +of two parts, a map of the elevation in the study area showing the survey line and a |
| 9 | +Cartesian plot showing the elevation along the survey line. |
12 | 10 |
|
13 | 11 | *This example is orientated on an example in the GMT/China documentation*:
|
14 | 12 | https://docs.gmt-china.org/latest/examples/ex026/
|
|
27 | 25 | # ----------------------------------------------------------------------------
|
28 | 26 | # Bottom: Map of elevation in study area
|
29 | 27 |
|
30 |
| -# Set up basic map |
31 |
| -fig.basemap( |
32 |
| - region=region_map, |
33 |
| - projection="M12c", # Mercator projection with a width of 12 centimeters |
34 |
| - frame="af", |
35 |
| -) |
| 28 | +# Set up basic map using a Mercator projection with a width of 12 centimeters |
| 29 | +fig.basemap(region=region_map, projection="M12c", frame="af") |
36 | 30 |
|
37 |
| -# Download grid for Earth relief with a resolution of 10 arc-minutes and |
38 |
| -# gridline registration [Default] |
39 |
| -grid_map = pygmt.datasets.load_earth_relief( |
40 |
| - resolution="10m", |
41 |
| - region=region_map, |
42 |
| -) |
| 31 | +# Download grid for Earth relief with a resolution of 10 arc-minutes and gridline |
| 32 | +# registration [Default] |
| 33 | +grid_map = pygmt.datasets.load_earth_relief(resolution="10m", region=region_map) |
43 | 34 |
|
44 | 35 | # Plot the downloaded grid with color-coding based on the elevation
|
45 | 36 | fig.grdimage(grid=grid_map, cmap="oleron")
|
46 | 37 |
|
47 | 38 | # Add a colorbar for the elevation
|
48 | 39 | fig.colorbar(
|
49 |
| - # Place the colorbar inside the plot (lower-case "j") in the Bottom |
50 |
| - # Right (BR) corner with an offset ("+o") of 0.7 centimeters and |
51 |
| - # 0.3 centimeters in x or y directions, respectively |
52 |
| - # Move the x label above the horizontal colorbar ("+ml") |
| 40 | + # Place the colorbar inside the plot (lower-case "j") in the Botton Right (BR) |
| 41 | + # corner with an offset ("+o") of 0.7 centimeters and 0.3 centimeters in x or y |
| 42 | + # directions, respectively; move the x label above the horizontal colorbar ("+ml") |
53 | 43 | position="jBR+o0.7c/0.8c+h+w5c/0.3c+ml",
|
54 |
| - # Add a box around the colobar with a fill ("+g") in "white" color and |
55 |
| - # a transparency ("@") of 30 % and with a 0.8-points thick black |
56 |
| - # outline ("+p") |
| 44 | + # Add a box around the colobar with a fill ("+g") in "white" color and a |
| 45 | + # transparency ("@") of 30 % and with a 0.8-points thick, black, outline ("+p") |
57 | 46 | box="+gwhite@30+p0.8p,black",
|
58 | 47 | # Add x and y labels ("+l")
|
59 | 48 | frame=["x+lElevation", "y+lm"],
|
|
63 | 52 | fig.plot(
|
64 | 53 | x=[126, 146], # Longitude in degrees East
|
65 | 54 | y=[42, 40], # Latitude in degrees North
|
66 |
| - # Draw a 2-points thick red dashed line for the survey line |
| 55 | + # Draw a 2-points thick, red, dashed line for the survey line |
67 | 56 | pen="2p,red,dashed",
|
68 | 57 | )
|
69 | 58 |
|
|
79 | 68 | # ----------------------------------------------------------------------------
|
80 | 69 | # Top: Elevation along survey line
|
81 | 70 |
|
82 |
| -# Shift plot origin 12.5 centimeters to the top |
83 |
| -fig.shift_origin(yshift="12.5c") |
| 71 | +# Shift plot origin to the top by the height of the map ("+h") plus 1.5 centimeters |
| 72 | +fig.shift_origin(yshift="h+1.5c") |
84 | 73 |
|
85 | 74 | fig.basemap(
|
86 | 75 | region=[0, 15, -8000, 6000], # x_min, x_max, y_min, y_max
|
87 |
| - # Cartesian projection with a width of 12 centimeters and |
88 |
| - # a height of 3 centimeters |
| 76 | + # Cartesian projection with a width of 12 centimeters and a height of 3 centimeters |
89 | 77 | projection="X12c/3c",
|
90 |
| - # Add annotations ("a") and ticks ("f") as well as labels ("+l") |
91 |
| - # at the west or left and south or bottom sides ("WSrt") |
| 78 | + # Add annotations ("a") and ticks ("f") as well as labels ("+l") at the west or |
| 79 | + # left and south or bottom sides ("WSrt") |
92 | 80 | frame=["WSrt", "xa2f1+lDistance+u°", "ya4000+lElevation / m"],
|
93 | 81 | )
|
94 | 82 |
|
|
101 | 89 | font="10p", # Use a font size of 10 points
|
102 | 90 | )
|
103 | 91 |
|
104 |
| -# Generate points along a great circle corresponding to the survey line |
105 |
| -# and store them in a pandas.DataFrame |
| 92 | +# Generate points along a great circle corresponding to the survey line and store them |
| 93 | +# in a pandas.DataFrame |
106 | 94 | track_df = pygmt.project(
|
107 |
| - center="126/42", # Start point of survey line (longitude/latitude) |
108 |
| - endpoint="146/40", # End point of survey line (longitude/latitude) |
109 |
| - generate="0.1", # Output data in steps of 0.1 degrees |
| 95 | + center=[126, 42], # Start point of survey line (longitude, latitude) |
| 96 | + endpoint=[146, 40], # End point of survey line (longitude, latitude) |
| 97 | + generate=0.1, # Output data in steps of 0.1 degrees |
110 | 98 | )
|
111 | 99 |
|
112 |
| -# Extract the elevation at the generated points from the downloaded grid |
113 |
| -# and add it as new column "elevation" to the pandas.DataFrame |
114 |
| -track_df = pygmt.grdtrack( |
115 |
| - grid=grid_map, |
116 |
| - points=track_df, |
117 |
| - newcolname="elevation", |
118 |
| -) |
| 100 | +# Extract the elevation at the generated points from the downloaded grid and add it as |
| 101 | +# new column "elevation" to the pandas.DataFrame |
| 102 | +track_df = pygmt.grdtrack(grid=grid_map, points=track_df, newcolname="elevation") |
119 | 103 |
|
120 | 104 | # Plot water masses
|
121 | 105 | fig.plot(
|
122 | 106 | x=[0, 15],
|
123 | 107 | y=[0, 0],
|
124 | 108 | fill="lightblue", # Fill the polygon in "lightblue"
|
125 |
| - # Draw a 0.25-points thick black solid outline |
| 109 | + # Draw a 0.25-points thick, black, solid outline |
126 | 110 | pen="0.25p,black,solid",
|
127 | 111 | close="+y-8000", # Force closed polygon
|
128 | 112 | )
|
|
132 | 116 | x=track_df.p,
|
133 | 117 | y=track_df.elevation,
|
134 | 118 | fill="gray", # Fill the polygon in "gray"
|
135 |
| - # Draw a 1-point thick black solid outline |
| 119 | + # Draw a 1-point thick, black, solid outline |
136 | 120 | pen="1p,black,solid",
|
137 | 121 | close="+y-8000", # Force closed polygon
|
138 | 122 | )
|
|
0 commit comments