Skip to content

Commit bd90727

Browse files
authored
Migrate frame settings to the Frame/Axis class [frame="a"] (#4529)
1 parent e35ebcd commit bd90727

14 files changed

Lines changed: 65 additions & 33 deletions

File tree

examples/gallery/seismology/meca.py

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

1414
# %%
1515
import pygmt
16+
from pygmt.params import Axis
1617

1718
fig = pygmt.Figure()
1819

@@ -23,7 +24,7 @@
2324
land="grey",
2425
water="lightblue",
2526
shorelines=True,
26-
frame="a",
27+
frame=Axis(annot=True),
2728
)
2829

2930
# Store focal mechanism parameters in a dictionary based on the Aki & Richards

examples/intro/02_contour_map.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
# %%
1212
import pygmt
13+
from pygmt.params import Axis
1314

1415
# %%
1516
# Loading the Earth relief dataset
@@ -43,7 +44,7 @@
4344
# "oleron" is used; a full list of CPTs can be found at :gmt-docs:`reference/cpts.html`.
4445

4546
fig = pygmt.Figure()
46-
fig.grdimage(grid=grid, frame="a", projection="M10c", cmap="SCM/oleron")
47+
fig.grdimage(grid=grid, frame=Axis(annot=True), projection="M10c", cmap="SCM/oleron")
4748
fig.show()
4849

4950

@@ -63,7 +64,7 @@
6364
# :meth:`pygmt.Figure.grdimage`.
6465

6566
fig = pygmt.Figure()
66-
fig.grdimage(grid=grid, frame="a", projection="M10c", cmap="SCM/oleron")
67+
fig.grdimage(grid=grid, frame=Axis(annot=True), projection="M10c", cmap="SCM/oleron")
6768
fig.colorbar(annot=1000, label="Elevation", unit="m")
6869
fig.show()
6970

@@ -84,7 +85,7 @@
8485
# lines can be adjusted (separately) by specifying the desired ``pen``.
8586

8687
fig = pygmt.Figure()
87-
fig.grdimage(grid=grid, frame="a", projection="M10c", cmap="SCM/oleron")
88+
fig.grdimage(grid=grid, frame=Axis(annot=True), projection="M10c", cmap="SCM/oleron")
8889
fig.grdcontour(grid=grid, levels=500, annotation=1000)
8990
fig.colorbar(annot=1000, label="Elevation", unit="m")
9091
fig.show()
@@ -99,7 +100,7 @@
99100
# the ``shorelines`` parameter draws a border around the islands.
100101

101102
fig = pygmt.Figure()
102-
fig.grdimage(grid=grid, frame="a", projection="M10c", cmap="SCM/oleron")
103+
fig.grdimage(grid=grid, frame=Axis(annot=True), projection="M10c", cmap="SCM/oleron")
103104
fig.grdcontour(grid=grid, levels=500, annotation=1000)
104105
fig.coast(shorelines="2p", land="lightgray")
105106
fig.colorbar(annot=1000, label="Elevation", unit="m")

examples/tutorials/advanced/earth_relief.py

Lines changed: 3 additions & 2 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
# Load sample Earth relief data for the entire globe at a resolution of 1 arc-degree.
@@ -90,11 +91,11 @@
9091
#
9192
# The example below uses data with a 10 arc-minutes resolution, and plots it on a
9293
# 15-centimeters-wide figure with a Mercator projection and a CPT set to *geo*.
93-
# ``frame="a"`` is used to add a frame with annotations to the figure.
94+
# ``frame=Axis(annot=True)`` is used to add a frame with annotations to the figure.
9495

9596
grid = pygmt.datasets.load_earth_relief(resolution="10m", region=[-14, 30, 35, 60])
9697
fig = pygmt.Figure()
97-
fig.grdimage(grid=grid, projection="M15c", frame="a", cmap="gmt/geo")
98+
fig.grdimage(grid=grid, projection="M15c", frame=Axis(annot=True), cmap="gmt/geo")
9899
fig.colorbar(annot=1000, label="Elevation", unit="m")
99100
fig.show()
100101

examples/tutorials/advanced/insets.py

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

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

1515
# %%
1616
# Prior to creating an inset figure, a larger figure must first be plotted. In the
@@ -25,7 +25,7 @@
2525
projection="M15c", # Set Mercator projection and size of 15 centimeter
2626
land="lightyellow", # Color land areas light yellow
2727
water="lightblue", # Color water areas light blue
28-
frame="a", # Set frame with annotation and major tick spacing
28+
frame=Axis(annot=True), # Set frame with annotations
2929
)
3030
fig.show()
3131

@@ -43,7 +43,7 @@
4343
projection="M15c",
4444
land="lightyellow",
4545
water="lightblue",
46-
frame="a",
46+
frame=Axis(annot=True),
4747
)
4848
with fig.inset(position=Position("BL"), width=3, box=Box(pen="black", fill="lightred")):
4949
# pass is used to exit the with statement as no plotting methods are called
@@ -65,7 +65,7 @@
6565
projection="M15c",
6666
land="lightyellow",
6767
water="lightblue",
68-
frame="a",
68+
frame=Axis(annot=True),
6969
)
7070
with fig.inset(
7171
position=Position("BL", offset=(0.5, 0.2)),
@@ -89,7 +89,7 @@
8989
projection="M15c",
9090
land="lightyellow",
9191
water="lightblue",
92-
frame="a",
92+
frame=Axis(annot=True),
9393
)
9494
# This does not include an inset fill as it is covered by the inset figure. Inset
9595
# width/height are determined by the ``region`` and ``projection`` parameters.

pygmt/src/coast.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ def coast( # noqa: PLR0913
211211
Example
212212
-------
213213
>>> import pygmt
214+
>>> from pygmt.params import Axis
214215
>>> # Create a new plot with pygmt.Figure()
215216
>>> fig = pygmt.Figure()
216217
>>> # Call the coast method for the plot
@@ -220,7 +221,7 @@ def coast( # noqa: PLR0913
220221
... # Set the region of the plot
221222
... region=[-10, 30, 30, 60],
222223
... # Set the frame of the plot, here annotations and major ticks
223-
... frame="a",
224+
... frame=Axis(annot=True),
224225
... # Set the color of the land to "darkgreen"
225226
... land="darkgreen",
226227
... # Set the color of the water to "lightblue"

pygmt/src/grdcontour.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def grdcontour(
129129
Example
130130
-------
131131
>>> import pygmt
132+
>>> from pygmt.params import Axis
132133
>>> # Load the 15 arc-minutes grid with "gridline" registration in the
133134
>>> # specified region
134135
>>> grid = pygmt.datasets.load_earth_relief(
@@ -147,7 +148,7 @@ def grdcontour(
147148
... # Set the interval for annotated contour lines at 1,000 meters
148149
... annotation=1000,
149150
... # Add a frame for the plot
150-
... frame="a",
151+
... frame=Axis(annot=True),
151152
... # Set the projection to Mercator for the 10 cm figure
152153
... projection="M10c",
153154
... )

pygmt/tests/test_coast.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66
from pygmt import Figure
77
from pygmt.exceptions import GMTParameterError
8+
from pygmt.params import Axis
89

910

1011
@pytest.mark.benchmark
@@ -52,7 +53,7 @@ def test_coast_dcw_single():
5253
fig = Figure()
5354
fig.coast(
5455
region=[-10, 15, 25, 44],
55-
frame="a",
56+
frame=Axis(annot=True),
5657
projection="M15c",
5758
land="brown",
5859
dcw="ES+gbisque+pblue",
@@ -68,7 +69,7 @@ def test_coast_dcw_list():
6869
fig = Figure()
6970
fig.coast(
7071
region=[-10, 15, 25, 44],
71-
frame="a",
72+
frame=Axis(annot=True),
7273
projection="M15c",
7374
land="brown",
7475
dcw=["ES+gbisque+pgreen", "IT+gcyan+pblue"],

pygmt/tests/test_colorbar.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66
from pygmt import Figure
77
from pygmt.exceptions import GMTParameterError
8+
from pygmt.params import Axis
89
from pygmt.params.position import Position
910

1011

@@ -30,7 +31,7 @@ def test_colorbar_shading_list():
3031
Create colorbar and set shading by passing the high/low values as a list.
3132
"""
3233
fig = Figure()
33-
fig.basemap(region=[0, 10, 0, 2], projection="X10c/2c", frame="a")
34+
fig.basemap(region=[0, 10, 0, 2], projection="X10c/2c", frame=Axis(annot=True))
3435
fig.colorbar(cmap="gmt/geo", shading=[-0.7, 0.2], frame=True)
3536
return fig
3637

pygmt/tests/test_contour.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pytest
1111
import xarray as xr
1212
from pygmt import Figure
13+
from pygmt.params import Axis
1314

1415
POINTS_DATA = Path(__file__).parent / "data" / "points.txt"
1516

@@ -44,7 +45,15 @@ def test_contour_vec(region):
4445
y = y.flatten()
4546
z = (x - 0.5 * (region[0] + region[1])) ** 2 + 4 * y**2
4647
z = np.exp(-z / 10**2 * np.log(2))
47-
fig.contour(x=x, y=y, z=z, projection="X10c", region=region, frame="a", pen=True)
48+
fig.contour(
49+
x=x,
50+
y=y,
51+
z=z,
52+
projection="X10c",
53+
region=region,
54+
frame=Axis(annot=True),
55+
pen=True,
56+
)
4857
return fig
4958

5059

@@ -160,7 +169,7 @@ def test_contour_incols_transposed_data(region):
160169
data,
161170
projection="X10c",
162171
region=region,
163-
frame="a",
172+
frame=Axis(annot=True),
164173
pen=True,
165174
incols=[1, 0, 2],
166175
)

pygmt/tests/test_grd2cpt.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pygmt.exceptions import GMTParameterError, GMTTypeError, GMTValueError
1010
from pygmt.helpers import GMTTempFile
1111
from pygmt.helpers.testing import load_static_earth_relief
12+
from pygmt.params import Axis
1213

1314

1415
@pytest.fixture(scope="module", name="grid")
@@ -27,9 +28,9 @@ def test_grd2cpt(grid):
2728
with a color bar.
2829
"""
2930
fig = Figure()
30-
fig.basemap(frame="a", projection="W0/15c", region="d")
31+
fig.basemap(frame=Axis(annot=True), projection="W0/15c", region="d")
3132
grd2cpt(grid=grid)
32-
fig.colorbar(frame="a")
33+
fig.colorbar(frame=Axis(annot=True))
3334
return fig
3435

3536

0 commit comments

Comments
 (0)