Skip to content

Commit 0bb6ba6

Browse files
authored
Migrate frame settings to the Frame/Axis class [frame='WSen' or similar] (#4534)
1 parent d4a006c commit 0bb6ba6

9 files changed

Lines changed: 45 additions & 28 deletions

File tree

examples/gallery/lines/line_segment_ends.py

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

1516
# Set up dictionary for colors
1617
dict_col = {
@@ -31,7 +32,7 @@
3132
x = np.array([30, 170])
3233
y = np.array([70, 70])
3334

34-
fig.basemap(region=[0, 260, 0, 100], projection="x1p", frame="rltb")
35+
fig.basemap(region=[0, 260, 0, 100], projection="x1p", frame=Frame(axes="rltb"))
3536

3637
for line_cap in ["butt", "round", "square"]:
3738
# Change GMT default locally
@@ -58,7 +59,7 @@
5859
x = np.array([5, 95, 65])
5960
y = np.array([10, 70, 10])
6061

61-
fig.basemap(region=[0, 260, 0, 100], projection="x1p", frame="rltb")
62+
fig.basemap(region=[0, 260, 0, 100], projection="x1p", frame=Frame(axes="rltb"))
6263

6364
for line_join in ["bevel", "round", "miter"]:
6465
with pygmt.config(PS_LINE_JOIN=line_join, PS_MITER_LIMIT=1):

examples/tutorials/advanced/grid_equalization.py

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

99
# %%
1010
import pygmt
11-
from pygmt.params import Position
11+
from pygmt.params import Frame, Position
1212

1313
# %%
1414
# Load sample data
@@ -43,7 +43,7 @@
4343
):
4444
# Plot the original digital elevation model in the first panel
4545
with fig.set_panel(panel=0):
46-
fig.grdimage(grid=grid, projection="M?", frame="WSne", cmap=True)
46+
fig.grdimage(grid=grid, projection="M?", frame=Frame(axes="WSne"), cmap=True)
4747
# Plot a histogram showing the z-value distribution in the original digital
4848
# elevation model
4949
with fig.set_panel(panel=1):
@@ -117,7 +117,7 @@
117117
):
118118
# Plot the grid with a linear distribution in the first panel
119119
with fig.set_panel(panel=0):
120-
fig.grdimage(grid=linear, projection="M?", frame="WSne", cmap=True)
120+
fig.grdimage(grid=linear, projection="M?", frame=Frame(axes="WSne"), cmap=True)
121121
# Plot a histogram showing the linear z-value distribution
122122
with fig.set_panel(panel=1):
123123
fig.histogram(
@@ -172,7 +172,7 @@
172172
):
173173
# Plot the grid with a normal distribution in the first panel
174174
with fig.set_panel(panel=0):
175-
fig.grdimage(grid=normal, projection="M?", frame="WSne", cmap=True)
175+
fig.grdimage(grid=normal, projection="M?", frame=Frame(axes="WSne"), cmap=True)
176176
# Plot a histogram showing the normal z-value distribution
177177
with fig.set_panel(panel=1):
178178
fig.histogram(
@@ -241,7 +241,9 @@
241241
):
242242
# Plot the grid with a quadratic distribution in the first panel
243243
with fig.set_panel(panel=0):
244-
fig.grdimage(grid=quadratic, projection="M?", frame="WSne", cmap=True)
244+
fig.grdimage(
245+
grid=quadratic, projection="M?", frame=Frame(axes="WSne"), cmap=True
246+
)
245247
# Plot a histogram showing the quadratic z-value distribution
246248
with fig.set_panel(panel=1):
247249
fig.histogram(

examples/tutorials/advanced/legends.py

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

1212
import pygmt
13-
from pygmt.params import Box, Position
13+
from pygmt.params import Box, Frame, Position
1414

1515
# %%
1616
# Create an auto-legend
@@ -51,7 +51,7 @@
5151
# drawn by default if ``position`` is used
5252

5353
fig = pygmt.Figure()
54-
fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame="rltb")
54+
fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame=Frame(axes="rltb"))
5555

5656
fig.plot(x=0, y=0, style="c0.25c", fill="orange", label="orange circle")
5757
fig.plot(x=1, y=0, style="t0.3c", fill="pink", pen="black", label="pink triangle")
@@ -62,7 +62,7 @@
6262
fig.legend(position=Position("TL", offset=(0.3, 0.2)))
6363

6464
fig.shift_origin(xshift="w+1c")
65-
fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame="rltb")
65+
fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame=Frame(axes="rltb"))
6666

6767
fig.plot(x=0, y=0, style="c0.25c", fill="orange", label="orange circle")
6868
fig.plot(x=1, y=0, style="t0.3c", fill="pink", pen="black", label="pink triangle")

examples/tutorials/advanced/subplots.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
# %%
2222
import pygmt
23+
from pygmt.params import Frame
2324

2425
# %%
2526
# Let's start by initializing a :class:`pygmt.Figure` instance.
@@ -39,17 +40,22 @@
3940
# %%
4041
# .. code-block:: default
4142
#
42-
# with fig.subplot(nrows=2, ncols=3, figsize=("15c", "6c"), frame="lrtb"):
43+
# with fig.subplot(
44+
# nrows=2,
45+
# ncols=3,
46+
# figsize=("15c", "6c"),
47+
# frame=Frame(axes="lrtb"),
48+
# ):
4349
# ...
4450

4551
# %%
4652
# will define our figure to have a 2 row and 3 column grid layout.
4753
# ``figsize=("15c", "6c")`` defines the overall size of the figure to be 15 cm wide by
48-
# 6 cm high. Using ``frame="lrtb"`` allows us to customize the map frame for all
49-
# subplots instead of setting them individually. The figure layout will look like the
50-
# following:
54+
# 6 cm high. Using ``frame=Frame(axes="lrtb")`` allows us to customize the map frame for
55+
# all subplots instead of setting them individually. The figure layout will look like
56+
# the following:
5157

52-
with fig.subplot(nrows=2, ncols=3, figsize=("15c", "6c"), frame="lrtb"):
58+
with fig.subplot(nrows=2, ncols=3, figsize=("15c", "6c"), frame=Frame(axes="lrtb")):
5359
for i in range(2): # row number starting from 0
5460
for j in range(3): # column number starting from 0
5561
index = i * 3 + j # index number starting from 0
@@ -169,7 +175,7 @@
169175
title="My Subplot Heading",
170176
sharex="b", # shared x-axis on the bottom side
171177
sharey="l", # shared y-axis on the left side
172-
frame="WSrt",
178+
frame=Frame(axes="WSrt"),
173179
):
174180
fig.basemap(region=[0, 10, 0, 10], projection="X?", panel=True)
175181
fig.basemap(region=[0, 20, 0, 10], projection="X?", panel=True)

examples/tutorials/basics/text.py

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

1212
import pygmt
13+
from pygmt.params import Axis, Frame
1314

1415
# %%
1516
# Adding a single text label
@@ -44,7 +45,7 @@
4445

4546
# -----------------------------------------------------------------------------
4647
# Left: "font", "angle", and "offset" parameters
47-
fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame="rtlb")
48+
fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame=Frame(axes="rtlb"))
4849

4950
# Change font size, family/weight, color of the text
5051
fig.text(x=0, y=3, text="my text", font="12p,Helvetica-Bold,blue")
@@ -64,7 +65,7 @@
6465

6566
# -----------------------------------------------------------------------------
6667
# Right: "justify" parameter
67-
fig.basemap(region=[-1, 1, -1, 1], projection="X5c", frame="rtlb")
68+
fig.basemap(region=[-1, 1, -1, 1], projection="X5c", frame=Frame(axes="rtlb"))
6869

6970
# Plot markers for reference
7071
fig.plot(
@@ -103,7 +104,7 @@
103104

104105
fig = pygmt.Figure()
105106

106-
fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame="rtlb")
107+
fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame=Frame(axes="rtlb"))
107108

108109
# Add a box with a fill in green color
109110
fig.text(x=0, y=3, text="My text", fill="green")
@@ -156,7 +157,7 @@
156157
# and ``justify`` parameters can be provided. Here, we give a complete example.
157158

158159
fig = pygmt.Figure()
159-
fig.basemap(region=[108, 121, -5, 8], projection="M10c", frame="a2f1")
160+
fig.basemap(region=[108, 121, -5, 8], projection="M10c", frame=Axis(annot=2, tick=1))
160161
fig.coast(land="darkgray", water="steelblue", shorelines="1/0.1p,gray30")
161162

162163
# Create space-delimited file with region / sea names:

pygmt/tests/test_legend.py

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

1314

1415
@pytest.fixture(scope="module", name="legend_spec")
@@ -119,7 +120,7 @@ def test_legend_width_height():
119120
"""
120121
)
121122
fig = Figure()
122-
fig.basemap(projection="x1c", region=[0, 20, 0, 20], frame="g1")
123+
fig.basemap(projection="x1c", region=[0, 20, 0, 20], frame=Axis(grid=1))
123124
# Default width and height
124125
fig.legend(spec, position="TL", box=True)
125126

pygmt/tests/test_subplot.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66
from pygmt import Figure
77
from pygmt.exceptions import GMTParameterError, GMTValueError
8-
from pygmt.params import Axis, Box, Position
8+
from pygmt.params import Axis, Box, Frame, Position
99

1010

1111
@pytest.mark.benchmark
@@ -17,7 +17,7 @@ def test_subplot_basic_frame():
1717
"""
1818
fig = Figure()
1919

20-
with fig.subplot(nrows=1, ncols=2, figsize=("6c", "3c"), frame="WSne"):
20+
with fig.subplot(nrows=1, ncols=2, figsize=("6c", "3c"), frame=Frame(axes="WSne")):
2121
with fig.set_panel(panel="0,0"):
2222
fig.basemap(region=[0, 3, 0, 3], frame="+tplot0")
2323
with fig.set_panel(panel=[0, 1]):
@@ -57,8 +57,8 @@ def test_subplot_tag_margins_title():
5757
margins=["0.3c", "0.1c"],
5858
title="Subplot Title",
5959
):
60-
fig.basemap(region=[0, 1, 2, 3], frame="WSne", panel=[0, 0])
61-
fig.basemap(region=[4, 5, 6, 7], frame="WSne", panel=[1, 0])
60+
fig.basemap(region=[0, 1, 2, 3], frame=Frame(axes="WSne"), panel=[0, 0])
61+
fig.basemap(region=[4, 5, 6, 7], frame=Frame(axes="WSne"), panel=[1, 0])
6262

6363
return fig
6464

@@ -75,7 +75,7 @@ def test_subplot_clearance_and_shared_xy_axis_layout():
7575
nrows=2,
7676
ncols=2,
7777
figsize=("5c", "5c"),
78-
frame="WSrt",
78+
frame=Frame(axes="WSrt"),
7979
clearance=["s0.2c", "n0.2c"],
8080
sharex="t",
8181
sharey=True,

pygmt/tests/test_timestamp.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

910

1011
@pytest.fixture(scope="module", name="faketime")
@@ -56,7 +57,7 @@ def test_timestamp_offset():
5657
Check if the "offset" parameter works.
5758
"""
5859
fig = Figure()
59-
fig.basemap(projection="X10c/5c", region=[0, 10, 0, 5], frame="g1")
60+
fig.basemap(projection="X10c/5c", region=[0, 10, 0, 5], frame=Axis(grid=1))
6061
for offset in ["1c", "1c/2c", ("1c", "3c"), 4, (4, 1)]:
6162
fig.timestamp(offset=offset, timefmt=f"offset={offset}")
6263
return fig

pygmt/tests/test_vlines.py

Lines changed: 6 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 GMTValueError
8+
from pygmt.params import Axis
89

910

1011
@pytest.mark.mpl_image_compare
@@ -61,7 +62,11 @@ def test_vlines_geographic_global():
6162
Plot vertical lines in geographic coordinates.
6263
"""
6364
fig = Figure()
64-
fig.basemap(region=[-180, 180, -90, 90], projection="R15c", frame="a30g30")
65+
fig.basemap(
66+
region=[-180, 180, -90, 90],
67+
projection="R15c",
68+
frame=Axis(annot=30, grid=30),
69+
)
6570
fig.vlines(30, pen="1p")
6671
fig.vlines(90, ymin=-60, pen="1p,blue")
6772
fig.vlines(-90, ymax=60, pen="1p,blue")

0 commit comments

Comments
 (0)