Skip to content

Commit 871bb8e

Browse files
authored
Migrate frame settings to the Frame/Axis class [frame='ag' and frame='g'] (#4533)
1 parent d435152 commit 871bb8e

8 files changed

Lines changed: 43 additions & 28 deletions

File tree

examples/gallery/images/contours.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# %%
2424
import numpy as np
2525
import pygmt
26+
from pygmt.params import Axis
2627

2728
# Build the contours underlying data with the function z = x^2 + y^2
2829
X, Y = np.meshgrid(np.linspace(-10, 10, 50), np.linspace(-10, 10, 50))
@@ -34,7 +35,7 @@
3435
fig.contour(
3536
region=[-10, 10, -10, 10],
3637
projection="X10c/10c",
37-
frame="ag",
38+
frame=Axis(annot=True, grid=True),
3839
pen="0.5p",
3940
# Pass the data as 3 1-D data columns
4041
x=x,

examples/gallery/symbols/bars.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
# %%
2323
import pygmt
24+
from pygmt.params import Axis
2425

2526
fig = pygmt.Figure()
2627

@@ -30,7 +31,7 @@
3031
nrows=2,
3132
ncols=2,
3233
subsize=("8c", "4c"),
33-
frame="ag",
34+
frame=Axis(annot=True, grid=True),
3435
sharey=True,
3536
sharex=True,
3637
margins=["0.5c", "0.75c"],

examples/tutorials/advanced/vectors.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
fig.plot(
3737
region=[0, 10, 0, 10],
3838
projection="X10c/10c",
39-
frame="ag",
39+
frame=Axis(annot=True, grid=True),
4040
x=2,
4141
y=8,
4242
style="v0c",
@@ -60,7 +60,7 @@
6060
fig.plot(
6161
region=[0, 10, 0, 10],
6262
projection="X10c/10c",
63-
frame="ag",
63+
frame=Axis(annot=True, grid=True),
6464
x=[2, 4],
6565
y=[8, 1],
6666
style="v0.6c+e",
@@ -85,7 +85,7 @@
8585
fig.plot(
8686
region=[0, 10, 0, 10],
8787
projection="X5i/5i",
88-
frame="ag",
88+
frame=Axis(annot=True, grid=True),
8989
x=2,
9090
y=8,
9191
style="v1c+e",
@@ -122,7 +122,7 @@
122122
fig.plot(
123123
region=[0, 10, 0, 10],
124124
projection="X10c/10c",
125-
frame="ag",
125+
frame=Axis(annot=True, grid=True),
126126
data=vectors,
127127
style="v0.6c+e",
128128
pen="2p",
@@ -148,7 +148,7 @@
148148
fig.plot(
149149
region=[0, 10, 0, 10],
150150
projection="X10c/10c",
151-
frame="ag",
151+
frame=Axis(annot=True, grid=True),
152152
data=vectors,
153153
style="v0.6c+e",
154154
pen="2p",
@@ -174,7 +174,7 @@
174174
fig.coast(
175175
region=[-127, -64, 24, 53],
176176
projection="M10c",
177-
frame="ag",
177+
frame=Axis(annot=True, grid=True),
178178
borders=1,
179179
shorelines="0.25p,black",
180180
area_thresh=4000,
@@ -268,7 +268,7 @@
268268
fig.plot(
269269
region=[-5, 5, -5, 5],
270270
projection="X10c",
271-
frame="ag",
271+
frame=Axis(annot=True, grid=True),
272272
data=data,
273273
style="m0.5c+ea",
274274
pen="2p",
@@ -308,7 +308,7 @@
308308
fig.plot(
309309
region=[-5, 5, -5, 5],
310310
projection="X10c",
311-
frame="ag",
311+
frame=Axis(annot=True, grid=True),
312312
data=data,
313313
style="m0.5c+ea",
314314
pen="2p",
@@ -330,7 +330,7 @@
330330
fig.plot(
331331
region=[0, 10, 0, 10],
332332
projection="X10c",
333-
frame="ag",
333+
frame=Axis(annot=True, grid=True),
334334
data=[circular_vector],
335335
style="m0.5c+ea",
336336
pen="2p",

examples/tutorials/advanced/working_with_panel.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import numpy as np
2626
import panel as pn
2727
import pygmt
28+
from pygmt.params import Axis
2829

2930
pn.extension()
3031

@@ -47,7 +48,7 @@
4748
# 15° North and a width of 12 centimeters
4849
projection="G0/15/12c",
4950
region="g", # global
50-
frame="g30", # Add frame and gridlines in steps of 30 degrees on top
51+
frame=Axis(grid=30), # Add gridlines in steps of 30 degrees on top
5152
land="gray", # Color land masses in "gray"
5253
water="lightblue", # Color water masses in "lightblue"
5354
# Add coastlines with a 0.25-point thick pen in "gray50"
@@ -84,7 +85,7 @@ def view(central_lon):
8485
# Vary the central longitude used for the Orthographic projection
8586
projection=f"G{central_lon}/15/12c",
8687
region="g",
87-
frame="g30",
88+
frame=Axis(grid=30),
8889
land="gray",
8990
water="lightblue",
9091
shorelines="1/0.25p,gray50",
@@ -133,7 +134,7 @@ def view(central_lon):
133134
region="g",
134135
grid=grd_relief, # Use grid downloaded above
135136
cmap=True, # Use colormap defined above
136-
frame="g30",
137+
frame=Axis(grid=30),
137138
)
138139
# Add a horizontal colorbar for the elevation.
139140
fig.colorbar(annot=2000, tick=1000, label="Elevation", unit="m")

examples/tutorials/basics/frames.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
# %%
1111
import pygmt
12+
from pygmt.params import Axis
1213

1314
# %%
1415
# Plot frame
@@ -51,7 +52,7 @@
5152

5253
fig = pygmt.Figure()
5354
fig.coast(shorelines="1/0.5p", region=[-180, 180, -60, 60], projection="M25c")
54-
fig.basemap(frame="ag")
55+
fig.basemap(frame=Axis(annot=True, grid=True))
5556
fig.show()
5657

5758
# %%

examples/tutorials/basics/regions.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
# %%
1111
import pygmt
12+
from pygmt.params import Axis
1213

1314
# %%
1415
# Coordinates
@@ -32,7 +33,7 @@
3233
# Display the shorelines and set the pen thickness to 0.5p
3334
shorelines="1/0.5p",
3435
# Set the frame to display annotations and gridlines
35-
frame="ag",
36+
frame=Axis(annot=True, grid=True),
3637
)
3738
fig.show()
3839

@@ -49,7 +50,7 @@
4950
water="white",
5051
borders="1/0.5p",
5152
shorelines="1/0.5p",
52-
frame="ag",
53+
frame=Axis(annot=True, grid=True),
5354
)
5455
fig.show()
5556

@@ -69,7 +70,7 @@
6970
water="white",
7071
borders="1/0.5p",
7172
shorelines="1/0.5p",
72-
frame="ag",
73+
frame=Axis(annot=True, grid=True),
7374
)
7475
fig.show()
7576

@@ -93,7 +94,7 @@
9394
water="white",
9495
borders="1/0.5p",
9596
shorelines="1/0.5p",
96-
frame="ag",
97+
frame=Axis(annot=True, grid=True),
9798
)
9899
fig.show()
99100

@@ -111,7 +112,7 @@
111112
water="white",
112113
borders="1/0.5p",
113114
shorelines="1/0.5p",
114-
frame="ag",
115+
frame=Axis(annot=True, grid=True),
115116
)
116117
fig.show()
117118

@@ -133,7 +134,7 @@
133134
water="white",
134135
borders="1/0.5p",
135136
shorelines="1/0.5p",
136-
frame="ag",
137+
frame=Axis(annot=True, grid=True),
137138
)
138139
fig.show()
139140

@@ -154,7 +155,7 @@
154155
water="white",
155156
borders="1/0.5p",
156157
shorelines="1/0.5p",
157-
frame="ag",
158+
frame=Axis(annot=True, grid=True),
158159
)
159160
fig.show()
160161

@@ -173,7 +174,7 @@
173174
water="white",
174175
borders="1/0.5p",
175176
shorelines="1/0.5p",
176-
frame="ag",
177+
frame=Axis(annot=True, grid=True),
177178
)
178179
fig.show()
179180

@@ -193,7 +194,7 @@
193194
water="white",
194195
borders="1/0.5p",
195196
shorelines="1/0.5p",
196-
frame="ag",
197+
frame=Axis(annot=True, grid=True),
197198
)
198199
fig.show()
199200

@@ -211,7 +212,7 @@
211212
water="white",
212213
borders="1/0.5p",
213214
shorelines="1/0.5p",
214-
frame="ag",
215+
frame=Axis(annot=True, grid=True),
215216
)
216217
fig.show()
217218

@@ -231,6 +232,6 @@
231232
water="white",
232233
borders="1/0.5p",
233234
shorelines="1/0.5p",
234-
frame="ag",
235+
frame=Axis(annot=True, grid=True),
235236
)
236237
fig.show()

pygmt/src/grdimage.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,19 @@ def grdimage( # noqa: PLR0913
158158
Example
159159
-------
160160
>>> import pygmt
161+
>>> from pygmt.params import Axis
161162
>>> # load the 30 arc-minutes grid with "gridline" registration
162163
>>> grid = pygmt.datasets.load_earth_relief("30m", registration="gridline")
163164
>>> # create a new plot with pygmt.Figure()
164165
>>> fig = pygmt.Figure()
165166
>>> # pass in the grid and set the CPT to "geo"
166167
>>> # set the projection to Mollweide and the size to 10 cm
167-
>>> fig.grdimage(grid=grid, cmap="gmt/geo", projection="W10c", frame="ag")
168+
>>> fig.grdimage(
169+
... grid=grid,
170+
... cmap="gmt/geo",
171+
... projection="W10c",
172+
... frame=Axis(annot=True, grid=True),
173+
... )
168174
>>> # show the plot
169175
>>> fig.show()
170176
"""

pygmt/tests/test_contour.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ def test_contour_matrix(array_func, data, region):
6969
"""
7070
fig = Figure()
7171
fig.contour(
72-
data=array_func(data), projection="X10c", region=region, frame="ag", pen=True
72+
data=array_func(data),
73+
projection="X10c",
74+
region=region,
75+
frame=Axis(annot=True, grid=True),
76+
pen=True,
7377
)
7478
return fig
7579

0 commit comments

Comments
 (0)