Skip to content

Commit 2c93894

Browse files
authored
Migrate list-based frame settings to Frame/Axis syntax across examples and docs (#4536)
1 parent c75dc72 commit 2c93894

34 files changed

Lines changed: 410 additions & 124 deletions

examples/gallery/images/cross_section.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# %%
1616
import pygmt
17-
from pygmt.params import Axis, Box, Position
17+
from pygmt.params import Axis, Box, Frame, Position
1818

1919
# Define region of study area
2020
# lon_min, lon_max, lat_min, lat_max in degrees East and North
@@ -120,6 +120,12 @@
120120
# Add map frame
121121
# Add annotations ("a") and ticks ("f") as well as labels ("+l") at the west or left
122122
# and south or bottom sides ("WSrt")
123-
fig.basemap(frame=["WSrt", "xa2f1+lDistance+u°", "ya4000+lElevation / m"])
123+
fig.basemap(
124+
frame=Frame(
125+
axes="WSrt",
126+
xaxis=Axis(annot=2, tick=1, label="Distance", unit="°"),
127+
yaxis=Axis(annot=4000, label="Elevation / m"),
128+
)
129+
)
124130

125131
fig.show()

examples/gallery/images/grdclip.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
# %%
1212
import pygmt
13-
from pygmt.params.position import Position
13+
from pygmt.params import Axis, Frame, Position
1414

1515
fig = pygmt.Figure()
1616

@@ -24,7 +24,12 @@
2424
fig.basemap(
2525
region=region,
2626
projection="M12c",
27-
frame=["WSne+toriginal grid", "xa5f1", "ya2f1"],
27+
frame=Frame(
28+
axes="WSne",
29+
title="original grid",
30+
xaxis=Axis(annot=5, tick=1),
31+
yaxis=Axis(annot=2, tick=1),
32+
),
2833
)
2934
fig.grdimage(grid=grid, cmap="SCM/oleron")
3035

@@ -39,7 +44,12 @@
3944
fig.basemap(
4045
region=region,
4146
projection="M12c",
42-
frame=["wSne+tclipped grid", "xa5f1", "ya2f1"],
47+
frame=Frame(
48+
axes="wSne",
49+
title="clipped grid",
50+
xaxis=Axis(annot=5, tick=1),
51+
yaxis=Axis(annot=2, tick=1),
52+
),
4353
)
4454
fig.grdimage(grid=grid)
4555
fig.colorbar(

examples/gallery/images/grdgradient.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
# %%
1515
import pygmt
16-
from pygmt.params import Position
16+
from pygmt.params import Axis, Frame, Position
1717

1818
# Define region of interest around Yosemite valley
1919
region = [-119.825, -119.4, 37.6, 37.825]
@@ -35,7 +35,12 @@
3535
fig.grdimage(
3636
grid=grid,
3737
projection="M12c",
38-
frame=["WSrt+tOriginal Data Elevation Model", "xa0.1", "ya0.1"],
38+
frame=Frame(
39+
axes="WSrt",
40+
title="Original Data Elevation Model",
41+
xaxis=Axis(annot=0.1),
42+
yaxis=Axis(annot=0.1),
43+
),
3944
cmap=True,
4045
)
4146
fig.colorbar(
@@ -57,7 +62,9 @@
5762
fig.grdimage(
5863
grid=dgrid,
5964
projection="M12c",
60-
frame=["lSEt+tHillshade Map", "xa0.1", "ya0.1"],
65+
frame=Frame(
66+
axes="lSEt", title="Hillshade Map", xaxis=Axis(annot=0.1), yaxis=Axis(annot=0.1)
67+
),
6168
cmap=True,
6269
)
6370

examples/gallery/images/grdgradient_shading.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
# %%
2424
import pygmt
25-
from pygmt.params import Position
25+
from pygmt.params import Axis, Frame, Position
2626

2727
# Load the 3 arc-minutes global relief grid in the target area around Caucasus
2828
grid = pygmt.datasets.load_earth_relief(resolution="03m", region=[35, 50, 35, 45])
@@ -58,10 +58,10 @@
5858
grid=grid,
5959
shading=shade,
6060
projection="M?",
61-
frame=[
62-
"a4f2",
63-
f"+tazimuth={azi}, normalize={normalize}, amp={amp}",
64-
],
61+
frame=Frame(
62+
title=f"azimuth={azi}, normalize={normalize}, amp={amp}",
63+
axis=Axis(annot=4, tick=2),
64+
),
6565
cmap=True,
6666
panel=True,
6767
)

examples/gallery/images/rgb_image.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# %%
1919
import pygmt
2020
import rioxarray
21+
from pygmt.params import Axis, Frame
2122

2223
# %%
2324
# Read 3-band data from GeoTIFF into an xarray.DataArray object:
@@ -38,6 +39,10 @@
3839
grid=image,
3940
# Use a map scale where 1 cm on the map equals 1 km on the ground
4041
projection="x1:100000",
41-
frame=[r"WSne+tL@!a¯hain@!a¯, Hawai`i on 9 Aug 2023", "af"],
42+
frame=Frame(
43+
axes="WSne",
44+
title=r"L@!a¯hain@!a¯, Hawai`i on 9 Aug 2023",
45+
axis=Axis(annot=True, tick=True),
46+
),
4247
)
4348
fig.show()

examples/gallery/lines/connection_lines.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
# %%
1313
import pygmt
14+
from pygmt.params import Axis, Frame
1415

1516
# Set up same sample data
1617
x = [2.2, 3.3, -3.1, -3.7, -0.1]
@@ -21,7 +22,11 @@
2122

2223
# -----------------------------------------------------------------------------
2324
# Left: record order
24-
fig.basemap(region=[-5, 5, -5, 5], projection="X6c", frame=["WSne", "af"])
25+
fig.basemap(
26+
region=[-5, 5, -5, 5],
27+
projection="X6c",
28+
frame=Frame(axes="WSne", axis=Axis(annot=True, tick=True)),
29+
)
2530

2631
# Connect data points based on the record order [Default connection=None]
2732
fig.plot(x=x, y=y, pen="1.5p,dodgerblue")
@@ -32,7 +37,11 @@
3237

3338
# -----------------------------------------------------------------------------
3439
# Middle: network
35-
fig.basemap(region=[-5, 5, -5, 5], projection="X6c", frame=["wSne", "af"])
40+
fig.basemap(
41+
region=[-5, 5, -5, 5],
42+
projection="X6c",
43+
frame=Frame(axes="wSne", axis=Axis(annot=True, tick=True)),
44+
)
3645

3746
# Connect data points as network
3847
fig.plot(x=x, y=y, pen="1.5p,dodgerblue", connection="n")
@@ -43,7 +52,11 @@
4352

4453
# -----------------------------------------------------------------------------
4554
# Right: reference point
46-
fig.basemap(region=[-5, 5, -5, 5], projection="X6c", frame=["wSne", "af"])
55+
fig.basemap(
56+
region=[-5, 5, -5, 5],
57+
projection="X6c",
58+
frame=Frame(axes="wSne", axis=Axis(annot=True, tick=True)),
59+
)
4760

4861
# Connect data points with the reference point (0,0)
4962
fig.plot(x=x, y=y, pen="1.5p,dodgerblue", connection="p0/0")

examples/gallery/lines/envelope.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# %%
1212
import pandas as pd
1313
import pygmt
14+
from pygmt.params import Axis, Frame
1415

1516
# Define a pandas.DataFrame with columns for x and y as well as the lower and upper
1617
# deviations
@@ -41,7 +42,12 @@
4142
fig.basemap(
4243
region=[0, 10, -1.5, 1.5],
4344
projection="X10c",
44-
frame=["WSne+tsymmetric deviations +d", "xa2f1", "ya1f0.1"],
45+
frame=Frame(
46+
axes="WSne",
47+
title="symmetric deviations +d",
48+
xaxis=Axis(annot=2, tick=1),
49+
yaxis=Axis(annot=1, tick=0.1),
50+
),
4551
)
4652

4753
# Plot a symmetrical envelope based on the deviations ("+d")
@@ -64,7 +70,12 @@
6470
fig.basemap(
6571
region=[0, 10, -1.5, 1.5],
6672
projection="X10c",
67-
frame=["WSne+tasymmetric deviations +D", "xa2f1", "yf0.1"],
73+
frame=Frame(
74+
axes="WSne",
75+
title="asymmetric deviations +D",
76+
xaxis=Axis(annot=2, tick=1),
77+
yaxis=Axis(tick=0.1),
78+
),
6879
)
6980

7081
# Plot an asymmetrical envelope based on the deviations ("+D")
@@ -87,7 +98,12 @@
8798
region=[0, 10, -1.5, 1.5],
8899
projection="X10c",
89100
# Use "\\053" to handle "+b" as a string not as a modifier
90-
frame=["wSnE+tbounds \\053b", "xa2f1", "ya1f0.1"],
101+
frame=Frame(
102+
axes="wSnE",
103+
title="bounds \\053b",
104+
xaxis=Axis(annot=2, tick=1),
105+
yaxis=Axis(annot=1, tick=0.1),
106+
),
91107
)
92108

93109
# Plot an envelope based on the bounds ("+b")

examples/gallery/lines/hlines_vlines.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
# In Cartesian coordinate systems lines are plotted as straight lines.
1313

1414
import pygmt
15-
from pygmt.params import Box, Position
15+
from pygmt.params import Axis, Box, Frame, Position
1616

1717
fig = pygmt.Figure()
1818

1919
fig.basemap(
20-
region=[0, 10, 0, 10], projection="X10c/10c", frame=["+tCartesian hlines", "af"]
20+
region=[0, 10, 0, 10],
21+
projection="X10c/10c",
22+
frame=Frame(title="Cartesian hlines", axis=Axis(annot=True, tick=True)),
2123
)
2224

2325
# Add a horizontal line at y=9
@@ -37,7 +39,9 @@
3739
fig.shift_origin(xshift="w+2c")
3840

3941
fig.basemap(
40-
region=[0, 10, 0, 10], projection="X10c/10c", frame=["+tCartesian vlines", "af"]
42+
region=[0, 10, 0, 10],
43+
projection="X10c/10c",
44+
frame=Frame(title="Cartesian vlines", axis=Axis(annot=True, tick=True)),
4145
)
4246
# Add a vertical line at x=1
4347
fig.vlines(x=1, pen="1.5p,red3", label="Line 1")
@@ -64,7 +68,11 @@
6468

6569
fig = pygmt.Figure()
6670

67-
fig.basemap(region="g", projection="R15c", frame=["+tGeographic hlines", "af"])
71+
fig.basemap(
72+
region="g",
73+
projection="R15c",
74+
frame=Frame(title="Geographic hlines", axis=Axis(annot=True, tick=True)),
75+
)
6876
# Add a line at 70°N
6977
fig.hlines(y=70, pen="1.5p,red3", label="Line 1")
7078
# Add a line at 50°N with longitude limits at 20°E and 160°E
@@ -75,7 +83,11 @@
7583

7684
fig.shift_origin(xshift="w+2c")
7785

78-
fig.basemap(region="g", projection="R15c", frame=["+tGeographic vlines", "af"])
86+
fig.basemap(
87+
region="g",
88+
projection="R15c",
89+
frame=Frame(title="Geographic vlines", axis=Axis(annot=True, tick=True)),
90+
)
7991
# Add a line at 70°E
8092
fig.vlines(x=70, pen="1.5p,red3", label="Line 1")
8193
# Add a line at 20°E with latitude limits at 50°S and 70°N
@@ -95,7 +107,11 @@
95107

96108
fig = pygmt.Figure()
97109

98-
fig.basemap(region=[0, 360, 0, 1], projection="P10c", frame=["+tPolar hlines", "af"])
110+
fig.basemap(
111+
region=[0, 360, 0, 1],
112+
projection="P10c",
113+
frame=Frame(title="Polar hlines", axis=Axis(annot=True, tick=True)),
114+
)
99115
# Add a line along radius=0.8
100116
fig.hlines(y=0.8, pen="1.5p,red3", label="Line 1")
101117
# Add a line along radius=0.5 with azimuth limits at 30° and 160°
@@ -106,7 +122,11 @@
106122

107123
fig.shift_origin(xshift="w+2c")
108124

109-
fig.basemap(region=[0, 360, 0, 1], projection="P10c", frame=["+tPolar vlines", "af"])
125+
fig.basemap(
126+
region=[0, 360, 0, 1],
127+
projection="P10c",
128+
frame=Frame(title="Polar vlines", axis=Axis(annot=True, tick=True)),
129+
)
110130
# Add a line along azimuth=120°
111131
fig.vlines(x=120, pen="1.5p,red3", label="Line 1")
112132
# Add a line along azimuth=190° with radius limits at 0.2 and 0.8

examples/gallery/lines/line_custom_cpt.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515
# %%
1616
import numpy as np
1717
import pygmt
18+
from pygmt.params import Axis, Frame
1819

1920
# Create a list of values between 20 and 30 with 0.2 intervals
2021
x = np.arange(start=20, stop=30, step=0.2)
2122

2223
fig = pygmt.Figure()
23-
fig.basemap(frame=["WSne", "af"], region=[20, 30, -10, 10])
24+
fig.basemap(
25+
frame=Frame(axes="WSne", axis=Axis(annot=True, tick=True)), region=[20, 30, -10, 10]
26+
)
2427

2528
# Create a custom CPT with the batlow CPT and 10 discrete z-values (colors),
2629
# use color_model="+c0-9" to write the color palette in categorical format and

examples/gallery/lines/wiggle.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@
1212
# %%
1313
import numpy as np
1414
import pygmt
15-
from pygmt.params import Position
15+
from pygmt.params import Axis, Frame, Position
1616

1717
# Create (x, y, z) triplets
1818
x = np.arange(-7, 7, 0.1)
1919
y = np.zeros(x.size)
2020
z = 50 * np.exp(-((x / 3) ** 2)) * np.cos(2 * np.pi * x)
2121

2222
fig = pygmt.Figure()
23-
fig.basemap(region=[-8, 12, -1, 1], projection="X10c", frame=["Snlr", "xa2f1"])
23+
fig.basemap(
24+
region=[-8, 12, -1, 1],
25+
projection="X10c",
26+
frame=Frame(axes="Snlr", xaxis=Axis(annot=2, tick=1)),
27+
)
2428
fig.wiggle(
2529
x=x,
2630
y=y,

0 commit comments

Comments
 (0)