Skip to content
Merged
Changes from 14 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
679ccf9
Add basic code
yvonnefroehlich Apr 24, 2023
588eec8
Add introduction
yvonnefroehlich Apr 24, 2023
86ee2fb
Add first comments to code
yvonnefroehlich Apr 24, 2023
8807d26
Replace tabs by four spaces
yvonnefroehlich Apr 24, 2023
02e3a44
Rename 'track.py' -> 'cross_section.py'
yvonnefroehlich Apr 24, 2023
50fdb76
[format-command] fixes
actions-bot Apr 24, 2023
9f82ebc
Add more comments to code
yvonnefroehlich Apr 24, 2023
9ca69d2
Replace tabs by four spaces
yvonnefroehlich Apr 24, 2023
1ec8745
Fix typo
yvonnefroehlich Apr 24, 2023
a7573af
Improve formulation
yvonnefroehlich Apr 24, 2023
554f750
Merge branch 'main' into rewrite-ex026-to-pygmt
yvonnefroehlich May 2, 2023
b884167
Improve formulation of reference to GMT/China docs
yvonnefroehlich May 2, 2023
68ec873
Remove trailing white space
yvonnefroehlich May 2, 2023
209cfb7
Reduce resolution temporarly
May 3, 2023
dbf4e82
Remove 'r' at the beginning of the docstrings
yvonnefroehlich May 7, 2023
f2f8429
Improve comments
yvonnefroehlich May 7, 2023
1a2dc75
Adjust comments temporaly
yvonnefroehlich May 7, 2023
321ca29
Improve comments
yvonnefroehlich May 7, 2023
4f5e6e7
Merge branch 'main' into rewrite-ex026-to-pygmt
yvonnefroehlich May 14, 2023
387eb87
Improve comment for track labels
yvonnefroehlich May 14, 2023
03aacf2
Improve comment for track labels
yvonnefroehlich May 14, 2023
84a766c
Fix line length - shorten comment
yvonnefroehlich May 14, 2023
ad23ec9
Fix line length - shorten comment
yvonnefroehlich May 14, 2023
8ed29b6
Merge branch 'main' into rewrite-ex026-to-pygmt
yvonnefroehlich May 27, 2023
87077fa
Merge branch 'main' into rewrite-ex026-to-pygmt
yvonnefroehlich Jun 4, 2023
f9bccb8
Expand introduction and comments
yvonnefroehlich Jun 11, 2023
9c294b5
Merge branch 'main' into rewrite-ex026-to-pygmt
yvonnefroehlich Jun 11, 2023
d102f7d
Improve comment
yvonnefroehlich Jun 11, 2023
6e88c97
Merge branch 'main' into rewrite-ex026-to-pygmt
yvonnefroehlich Jun 18, 2023
51f6373
Fix typo
yvonnefroehlich Jun 18, 2023
c535ac9
Merge branch 'main' into rewrite-ex026-to-pygmt
yvonnefroehlich Jun 21, 2023
f909f19
Fix typo introduction (code review)
yvonnefroehlich Jun 22, 2023
1f40002
Shorten comment (code review)
yvonnefroehlich Jun 22, 2023
c40401b
Remove not required word (code review)
yvonnefroehlich Jun 22, 2023
e6f716d
Add missing word (code review)
yvonnefroehlich Jun 22, 2023
70727e5
Remove not required word (code review)
yvonnefroehlich Jun 22, 2023
b0735ae
Remove colorbar (code review)
yvonnefroehlich Jun 22, 2023
992bd0c
Add colorbar immediately after grdimage (code review)
yvonnefroehlich Jun 22, 2023
116171b
Download grid only once (code review)
yvonnefroehlich Jun 22, 2023
5e4a497
Improve formulation for comment for colorbar argument
yvonnefroehlich Jun 22, 2023
98709d9
Merge branch 'main' into rewrite-ex026-to-pygmt
yvonnefroehlich Jun 22, 2023
f791a08
Reduce step size of survey line
yvonnefroehlich Jun 23, 2023
b142510
Update als comment to larger step size along survey line
yvonnefroehlich Jun 23, 2023
0cc6b9e
Comment code parts related to 'pygmt.grdtrack' out
yvonnefroehlich Jun 24, 2023
68bc2fd
Fix code style for comments
yvonnefroehlich Jun 24, 2023
a467834
Revert step size increase for survey line
yvonnefroehlich Jun 24, 2023
8bda00e
Merge branch 'main' into rewrite-ex026-to-pygmt
yvonnefroehlich Jul 3, 2023
5021879
Merge branch 'main' into rewrite-ex026-to-pygmt
yvonnefroehlich Aug 15, 2023
63b71ab
Un-comment only calculation of 'track_df' via 'grdtrack'
yvonnefroehlich Aug 19, 2023
a9f2e5d
Un-comment plotting 'track_df' via 'data' and 'incols'
yvonnefroehlich Aug 19, 2023
c25a778
Test plotting 'track_df' via 'x' and 'y'
yvonnefroehlich Aug 19, 2023
a5ce14f
Merge branch 'main' into rewrite-ex026-to-pygmt
yvonnefroehlich Aug 19, 2023
355831e
Merge branch 'main' into rewrite-ex026-to-pygmt
yvonnefroehlich Aug 20, 2023
ab5d52b
Test using 'int' with 'data' and 'incols'
yvonnefroehlich Aug 20, 2023
5fb3e49
Test using 'float' with 'data' and 'incols'
yvonnefroehlich Aug 20, 2023
b666712
Redo test changes and use 'x' and 'y'
yvonnefroehlich Aug 20, 2023
e18b6b2
Merge branch 'main' into rewrite-ex026-to-pygmt
yvonnefroehlich Aug 21, 2023
129c3fa
Merge branch 'main' into rewrite-ex026-to-pygmt
yvonnefroehlich Aug 21, 2023
765f2fd
Use '+u°' instead of '+u@.' following PR #2584
yvonnefroehlich Aug 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 131 additions & 0 deletions examples/gallery/images/cross_section.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
r"""
Cross-section along a transect
==============================
:func:`pygmt.project` and :func:`pygmt.grdtrack` can be used to estimate
a quantity along a track.
In this example, the elevation is extracted from a gird provided via
:func:`pygmt.datasets.load_earth_relief`.

TODO

*This example is orientated on an example in the GMT/China documentation*:
https://docs.gmt-china.org/latest/examples/ex026/
"""

import pygmt

# Define region of study area
region_map = [122, 149, 30, 49]

# Create a new instance or object of the pygmt.Figure() class
fig = pygmt.Figure()

# ----------------------------------------------------------------------------
# Bottom: Map

fig.basemap(
region=region_map,
projection="M12c", # Mercator projection with a width of 12 centimeters
frame="af",
)

# Download grid for Earth relief with a resolution of 10 arc-minutes and
# gridline registration [Default]
grid_map = pygmt.datasets.load_earth_relief(
resolution="10m",
region=region_map,
)

# Plot the downloaded grid with color-coding for the elevation
fig.grdimage(grid=grid_map, cmap="oleron")

# Choose a track
fig.plot(
x=[126, 146], # Longitude in degrees East
y=[42, 40], # Latitude in degrees North
# Draw a 2-points thick red dashed line for the track
pen="2p,red,dashed",
)

# Add labels for start and end points of the track
fig.text(
x=[126, 146],
y=[42, 40],
text=["A", "B"],
offset="0c/0.2c",
font="15p",
)

# Add a colorbar for the elevation
fig.colorbar(
position="jBR+o0.7c/0.8c+h+w5c/0.3c+ml",
box="+gwhite@30+p0.8p,black",
frame=["x+lElevation", "y+lm"],
)

# ----------------------------------------------------------------------------
# Top: Track

# Shift plot origin 12.5 centimeters to the top
fig.shift_origin(yshift="12.5c")

fig.basemap(
region=[0, 15, -8000, 6000],
# Carthesian projection with a width of 12 centimeters and
# a height of 3 centimeters
projection="X12/3c",
frame=["WSrt", "xa2f1+lDistance+u@.", "ya4000+lElevation / m"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put units in brackets. The ° symbol will need to wait for #2584 to work.

Suggested change
frame=["WSrt", "xa2f1+lDistance+u@.", "ya4000+lElevation / m"],
frame=["WSrt", "xa2f1+lDistance (°) +u@.", "ya4000+lElevation (m)"],

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the x-axis, there is already the unit degrees add by +u@. If +u° works after PR #2584, I can change this.

Hm, I am not sure about putting units in brackets, including both [ ] or ( ). I learned this is wrong, and quantity / unit or quantity in unit should be used. However, I see again and again figures which do not follow this rule, including figues in scientific publications. Sometimes already the individual guidelines of the journals do not follow this rule. Actually, we already have some examples, which show units in brackets. What do others think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, I'm not sure what convention there is for labelling units, maybe it is journal specific also? We can keep using slash if that is more appropriate. And the degree unit can be omitted since it's on the axis already, it's not often that I see distance units in arc degrees actually.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the x-axis, there is already the unit degrees add by +u@. If +u° works after PR #2584, I can change this.

Please see commit 765f2fd for this change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, I'm not sure what convention there is for labelling units, maybe it is journal specific also? We can keep using slash if that is more appropriate.

I learned this as an official rule during my studies, but it seems that this is not handled in such a strict way everywhere 😂.

)

# Add labels for start and end points of the track
fig.text(
x=[0, 15],
y=[7000, 7000],
text=["A", "B"],
no_clip=True, # Do not clip text that fall outside of the plot bounds
font="10p", # Use a font size of 10 points
)

# Set up track and store it in a DataFrame
track_df = pygmt.project(
center="126/42",
endpoint="146/40",
generate="0.1",
)

# Download grid for Earth relief with a resolution of 4 arc-minutes and
# gridline registration [Default]
grid_track = pygmt.datasets.load_earth_relief(
resolution="10m",
region=region_map,
)

# Extract the elevation along the defined track from the downloaded grid
# and add it as new column "elevation" to the DataFrame
track_df = pygmt.grdtrack(
grid=grid_track,
points=track_df,
newcolname="elevation",
)

# Plot water masses
fig.plot(
x=[0, 15],
y=[0, 0],
fill="lightblue", # Fill the polygon in "lightblue"
# Draw a 0.25-points thick black solid outline
pen="0.25p,black,solid",
close="+y-8000", # Force closed polygon
)

# Plot elevation along track
fig.plot(
data=track_df,
fill="gray", # Fill the polygon in "gray"
# Draw a 1-point thick black solid outline
pen="1p,black,solid",
close="+y-8000", # Force closed polygon
incols=[2, 3], # Select order of input columns (zero-based indexing)
)

fig.show()