-
Notifications
You must be signed in to change notification settings - Fork 245
Add gallery example "Cross-section along a transect" #2515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 19 commits
679ccf9
588eec8
86ee2fb
8807d26
02e3a44
50fdb76
9f82ebc
9ca69d2
1ec8745
a7573af
554f750
b884167
68ec873
209cfb7
dbf4e82
f2f8429
1a2dc75
321ca29
4f5e6e7
387eb87
03aacf2
84a766c
ad23ec9
8ed29b6
87077fa
f9bccb8
9c294b5
d102f7d
6e88c97
51f6373
c535ac9
f909f19
1f40002
c40401b
e6f716d
70727e5
b0735ae
992bd0c
116171b
5e4a497
98709d9
f791a08
b142510
0cc6b9e
68bc2fd
a467834
8bda00e
5021879
63b71ab
a9f2e5d
c25a778
a5ce14f
355831e
ab5d52b
5fb3e49
b666712
e18b6b2
129c3fa
765f2fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,131 @@ | ||||||
| """ | ||||||
| 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 | ||||||
|
yvonnefroehlich marked this conversation as resolved.
Outdated
|
||||||
| fig = pygmt.Figure() | ||||||
|
|
||||||
| # ---------------------------------------------------------------------------- | ||||||
| # Bottom: Map of elevation in study area | ||||||
|
|
||||||
| 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") | ||||||
|
yvonnefroehlich marked this conversation as resolved.
|
||||||
|
|
||||||
| # 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 | ||||||
|
yvonnefroehlich marked this conversation as resolved.
Outdated
|
||||||
| 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: Elevation along 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"], | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put units in brackets. The
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the x-axis, there is already the unit degrees add by Hm, I am not sure about putting units in brackets, including both
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I learned this as an official rule during my studies, but it seems that this is not handled in such a strict way everywhere 😂.
yvonnefroehlich marked this conversation as resolved.
Outdated
|
||||||
| ) | ||||||
|
|
||||||
| # Add labels for start and end points of the track | ||||||
|
yvonnefroehlich marked this conversation as resolved.
Outdated
|
||||||
| 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 | ||||||
|
yvonnefroehlich marked this conversation as resolved.
Outdated
|
||||||
| font="10p", # Use a font size of 10 points | ||||||
| ) | ||||||
|
|
||||||
| # Set up track and store it in a pandas.DataFrame | ||||||
| track_df = pygmt.project( | ||||||
| center="126/42", | ||||||
| endpoint="146/40", | ||||||
| generate="0.1", | ||||||
| ) | ||||||
|
|
||||||
| # Download grid for Earth relief with a resolution of 10 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 pandas.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() | ||||||
Uh oh!
There was an error while loading. Please reload this page.