Skip to content

Commit 671afc4

Browse files
DOC: Polish gallery example "Cross-section along a transect" (#3967)
1 parent 72e5c52 commit 671afc4

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

examples/gallery/images/cross_section.py

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
# lon_min, lon_max, lat_min, lat_max in degrees East and North
2020
region_map = [122, 149, 30, 49]
2121

22+
# Chose a survey line with start point A and end point B
23+
lonA, latA, lonB, latB = 126, 42, 146, 40 # noqa: N816
24+
2225
# Create a new pygmt.Figure instance
2326
fig = pygmt.Figure()
2427

@@ -39,30 +42,25 @@
3942
fig.colorbar(
4043
# Place the colorbar inside the plot (lowercase "j") in the Bottom Right (BR)
4144
# 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")
45+
# directions, respectively; move the x-label above the horizontal colorbar ("+ml")
4346
position="jBR+o0.7c/0.8c+h+w5c/0.3c+ml",
4447
# Add a box around the colobar with a fill ("+g") in "white" color and a
4548
# transparency ("@") of 30 % and with a 0.8-points thick, black, outline ("+p")
4649
box="+gwhite@30+p0.8p,black",
47-
# Add x and y labels ("+l")
50+
# Add x- and y-labels ("+l")
4851
frame=["x+lElevation", "y+lm"],
4952
)
5053

51-
# Choose a survey line
52-
fig.plot(
53-
x=[126, 146], # Longitude in degrees East
54-
y=[42, 40], # Latitude in degrees North
55-
# Draw a 2-points thick, red, dashed line for the survey line
56-
pen="2p,red,dashed",
57-
)
54+
# Plot the survey line
55+
fig.plot(x=[lonA, lonB], y=[latA, latB], pen="1p,red,solid")
5856

5957
# Add labels "A" and "B" for the start and end points of the survey line
6058
fig.text(
61-
x=[126, 146],
62-
y=[42, 40],
59+
x=[lonA, lonB],
60+
y=[latA, latB],
6361
text=["A", "B"],
64-
offset="0c/0.2c", # Move text 0.2 centimeters up (y-direction)
65-
font="15p", # Use a font size of 15 points
62+
offset="0c/0.3c", # Move text 0.2 centimeters up (y-direction)
63+
font="15p,red", # Use a red font with a size of 15 points
6664
)
6765

6866
# ----------------------------------------------------------------------------
@@ -75,9 +73,7 @@
7573
region=[0, 15, -8000, 6000], # x_min, x_max, y_min, y_max
7674
# Cartesian projection with a width of 12 centimeters and a height of 3 centimeters
7775
projection="X12c/3c",
78-
# Add annotations ("a") and ticks ("f") as well as labels ("+l") at the west or
79-
# left and south or bottom sides ("WSrt")
80-
frame=["WSrt", "xa2f1+lDistance+u°", "ya4000+lElevation / m"],
76+
frame=0,
8177
)
8278

8379
# Add labels "A" and "B" for the start and end points of the survey line
@@ -86,14 +82,14 @@
8682
y=[7000, 7000],
8783
text=["A", "B"],
8884
no_clip=True, # Do not clip text that fall outside the plot bounds
89-
font="10p", # Use a font size of 10 points
85+
font="10p,red",
9086
)
9187

9288
# Generate points along a great circle corresponding to the survey line and store them
9389
# in a pandas.DataFrame
9490
track_df = pygmt.project(
95-
center=[126, 42], # Start point of survey line (longitude, latitude)
96-
endpoint=[146, 40], # End point of survey line (longitude, latitude)
91+
center=[lonA, latA], # Start point of survey line (longitude, latitude)
92+
endpoint=[lonB, latB], # End point of survey line (longitude, latitude)
9793
generate=0.1, # Output data in steps of 0.1 degrees
9894
)
9995

@@ -106,19 +102,22 @@
106102
x=[0, 15],
107103
y=[0, 0],
108104
fill="lightblue", # Fill the polygon in "lightblue"
109-
# Draw a 0.25-points thick, black, solid outline
110-
pen="0.25p,black,solid",
105+
pen="0.25p,black,solid", # Draw a 0.25-points thick, black, solid outline
111106
close="+y-8000", # Force closed polygon
112107
)
113108

114109
# Plot elevation along the survey line
115110
fig.plot(
116111
x=track_df.p,
117112
y=track_df.elevation,
118-
fill="gray", # Fill the polygon in "gray"
119-
# Draw a 1-point thick, black, solid outline
120-
pen="1p,black,solid",
121-
close="+y-8000", # Force closed polygon
113+
fill="gray",
114+
pen="1p,red,solid",
115+
close="+y-8000",
122116
)
123117

118+
# Add map frame
119+
# Add annotations ("a") and ticks ("f") as well as labels ("+l") at the west or left
120+
# and south or bottom sides ("WSrt")
121+
fig.basemap(frame=["WSrt", "xa2f1+lDistance+u°", "ya4000+lElevation / m"])
122+
124123
fig.show()

0 commit comments

Comments
 (0)