Skip to content

Commit 7ec2a12

Browse files
yvonnefroehlichseismanmichaelgrund
authored
DOC/Gallery example "Cross-section along a transect": General improvements (#3623)
Co-authored-by: Dongdong Tian <[email protected]> Co-authored-by: Michael Grund <[email protected]>
1 parent 311b951 commit 7ec2a12

File tree

1 file changed

+31
-47
lines changed

1 file changed

+31
-47
lines changed

examples/gallery/images/cross_section.py

Lines changed: 31 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
Cross-section along a transect
33
==============================
44
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.
1210
1311
*This example is orientated on an example in the GMT/China documentation*:
1412
https://docs.gmt-china.org/latest/examples/ex026/
@@ -27,33 +25,24 @@
2725
# ----------------------------------------------------------------------------
2826
# Bottom: Map of elevation in study area
2927

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")
3630

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)
4334

4435
# Plot the downloaded grid with color-coding based on the elevation
4536
fig.grdimage(grid=grid_map, cmap="oleron")
4637

4738
# Add a colorbar for the elevation
4839
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")
5343
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")
5746
box="+gwhite@30+p0.8p,black",
5847
# Add x and y labels ("+l")
5948
frame=["x+lElevation", "y+lm"],
@@ -63,7 +52,7 @@
6352
fig.plot(
6453
x=[126, 146], # Longitude in degrees East
6554
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
6756
pen="2p,red,dashed",
6857
)
6958

@@ -79,16 +68,15 @@
7968
# ----------------------------------------------------------------------------
8069
# Top: Elevation along survey line
8170

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")
8473

8574
fig.basemap(
8675
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
8977
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")
9280
frame=["WSrt", "xa2f1+lDistance+u°", "ya4000+lElevation / m"],
9381
)
9482

@@ -101,28 +89,24 @@
10189
font="10p", # Use a font size of 10 points
10290
)
10391

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
10694
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
11098
)
11199

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")
119103

120104
# Plot water masses
121105
fig.plot(
122106
x=[0, 15],
123107
y=[0, 0],
124108
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
126110
pen="0.25p,black,solid",
127111
close="+y-8000", # Force closed polygon
128112
)
@@ -132,7 +116,7 @@
132116
x=track_df.p,
133117
y=track_df.elevation,
134118
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
136120
pen="1p,black,solid",
137121
close="+y-8000", # Force closed polygon
138122
)

0 commit comments

Comments
 (0)