Skip to content

Commit 2b96907

Browse files
authored
Migrate the box parameter to the new alias system (#4073)
1 parent f1d671f commit 2b96907

File tree

6 files changed

+76
-113
lines changed

6 files changed

+76
-113
lines changed

pygmt/src/coast.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
kwargs_to_strings,
1515
use_alias,
1616
)
17+
from pygmt.params import Box
1718

1819
__doctest_skip__ = ["coast"]
1920

@@ -24,7 +25,6 @@
2425
B="frame",
2526
C="lakes",
2627
E="dcw",
27-
F="box",
2828
G="land",
2929
I="rivers",
3030
L="map_scale",
@@ -41,6 +41,7 @@ def coast(
4141
resolution: Literal[
4242
"auto", "full", "high", "intermediate", "low", "crude", None
4343
] = None,
44+
box: Box | bool = False,
4445
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
4546
| bool = False,
4647
panel: int | tuple[int, int] | bool = False,
@@ -68,6 +69,7 @@ def coast(
6869
6970
{aliases}
7071
- D = resolution
72+
- F = box
7173
- J = projection
7274
- V = verbose
7375
- c = panel
@@ -127,24 +129,11 @@ def coast(
127129
map_scale : str
128130
[**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ *refpoint*\ **+w**\ *length*.
129131
Draw a simple map scale centered on the reference point specified.
130-
box : bool or str
131-
[**+c**\ *clearances*][**+g**\ *fill*][**+i**\ [[*gap*/]\ *pen*]]\
132-
[**+p**\ [*pen*]][**+r**\ [*radius*]][**+s**\ [[*dx*/*dy*/][*shade*]]].
133-
If set to ``True``, draw a rectangular border around the
134-
map scale or rose. Alternatively, specify a different pen with
135-
**+p**\ *pen*. Add **+g**\ *fill* to fill the scale panel [Default is
136-
no fill]. Append **+c**\ *clearance* where *clearance* is either gap,
137-
xgap/ygap, or lgap/rgap/bgap/tgap where these items are uniform,
138-
separate x and y, or individual side spacings between scale and
139-
border. Append **+i** to draw a secondary, inner border as well.
140-
We use a uniform gap between borders of 2 points and the
141-
:gmt-term:`MAP_DEFAULTS_PEN` unless other values are specified. Append
142-
**+r** to draw rounded rectangular borders instead, with a 6-points
143-
corner radius. You can override this radius by appending another value.
144-
Finally, append **+s** to draw an offset background shaded region.
145-
Here, *dx/dy* indicates the shift relative to the foreground frame
146-
[Default is ``"4p/-4p"``] and shade sets the fill style to use for
147-
shading [Default is ``"gray50"``].
132+
box
133+
Draw a background box behind the map scale or rose. If set to ``True``, a simple
134+
rectangular box is drawn using :gmt-term:`MAP_FRAME_PEN`. To customize the box
135+
appearance, pass a :class:`pygmt.params.Box` object to control style, fill, pen,
136+
and other box properties.
148137
borders : int, str, or list
149138
*border*\ [/*pen*].
150139
Draw political boundaries. Specify the type of boundary and
@@ -230,6 +219,7 @@ def coast(
230219
"crude": "c",
231220
},
232221
),
222+
F=Alias(box, name="box"),
233223
).add_common(
234224
J=projection,
235225
V=verbose,

pygmt/src/colorbar.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
from typing import Literal
66

7-
from pygmt.alias import AliasSystem
7+
from pygmt.alias import Alias, AliasSystem
88
from pygmt.clib import Session
99
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
10+
from pygmt.params import Box
1011

1112
__doctest_skip__ = ["colorbar"]
1213

@@ -16,7 +17,6 @@
1617
B="frame",
1718
C="cmap",
1819
D="position",
19-
F="box",
2020
G="truncate",
2121
I="shading",
2222
L="equalsize",
@@ -30,6 +30,7 @@
3030
def colorbar(
3131
self,
3232
projection=None,
33+
box: Box | bool = False,
3334
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
3435
| bool = False,
3536
panel: int | tuple[int, int] | bool = False,
@@ -50,6 +51,7 @@ def colorbar(
5051
Full GMT docs at :gmt-docs:`colorbar.html`.
5152
5253
{aliases}
54+
- F = box
5355
- J = projection
5456
- V = verbose
5557
- c = panel
@@ -82,23 +84,11 @@ def colorbar(
8284
be changed by appending **+j** followed by a
8385
:doc:`2-character justification code </techref/justification_codes>`
8486
*justify*.
85-
box : bool or str
86-
[**+c**\ *clearances*][**+g**\ *fill*][**+i**\ [[*gap*/]\ *pen*]]\
87-
[**+p**\ [*pen*]][**+r**\ [*radius*]][**+s**\ [[*dx*/*dy*/][*shade*]]].
88-
If set to ``True``, draw a rectangular border around the color scale.
89-
Alternatively, specify a different pen with **+p**\ *pen*. Add
90-
**+g**\ *fill* to fill the scale panel [Default is no fill]. Append
91-
**+c**\ *clearance* where *clearance* is either gap, xgap/ygap, or
92-
lgap/rgap/bgap/tgap where these items are uniform, separate in x- and
93-
y-direction, or individual side spacings between scale and border.
94-
Append **+i** to draw a secondary, inner border as well. We use a
95-
uniform gap between borders of 2p and the :gmt-term:`MAP_DEFAULTS_PEN`
96-
unless other values are specified. Append **+r** to draw rounded
97-
rectangular borders instead, with a 6p corner radius. You can override
98-
this radius by appending another value. Finally, append **+s** to draw
99-
an offset background shaded region. Here, *dx/dy* indicates the shift
100-
relative to the foreground frame [Default is ``"4p/-4p"``] and shade
101-
sets the fill style to use for shading [Default is ``"gray50"``].
87+
box
88+
Draw a background box behind the colorbar. If set to ``True``, a simple
89+
rectangular box is drawn using :gmt-term:`MAP_FRAME_PEN`. To customize the box
90+
appearance, pass a :class:`pygmt.params.Box` object to control style, fill, pen,
91+
and other box properties.
10292
truncate : list or str
10393
*zlo*/*zhi*.
10494
Truncate the incoming CPT so that the lowest and highest z-levels are
@@ -157,7 +147,9 @@ def colorbar(
157147
"""
158148
self._activate_figure()
159149

160-
aliasdict = AliasSystem().add_common(
150+
aliasdict = AliasSystem(
151+
F=Alias(box, name="box"),
152+
).add_common(
161153
J=projection,
162154
V=verbose,
163155
c=panel,

pygmt/src/image.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,20 @@
55
from typing import Literal
66

77
from pygmt._typing import PathLike
8-
from pygmt.alias import AliasSystem
8+
from pygmt.alias import Alias, AliasSystem
99
from pygmt.clib import Session
1010
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
11+
from pygmt.params import Box
1112

1213

1314
@fmt_docstring
14-
@use_alias(
15-
D="position",
16-
F="box",
17-
G="bitcolor",
18-
M="monochrome",
19-
R="region",
20-
p="perspective",
21-
)
15+
@use_alias(D="position", G="bitcolor", M="monochrome", R="region", p="perspective")
2216
@kwargs_to_strings(R="sequence", p="sequence")
2317
def image(
2418
self,
2519
imagefile: PathLike,
2620
projection=None,
21+
box: Box | bool = False,
2722
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
2823
| bool = False,
2924
panel: int | tuple[int, int] | bool = False,
@@ -39,6 +34,7 @@ def image(
3934
Full GMT docs at :gmt-docs:`image.html`.
4035
4136
{aliases}
37+
- F = box
4238
- J = projection
4339
- V = verbose
4440
- c = panel
@@ -59,11 +55,11 @@ def image(
5955
**+w**\ [**-**]\ *width*\ [/*height*]\ [**+j**\ *justify*]\
6056
[**+n**\ *nx*\ [/*ny*]]\ [**+o**\ *dx*\ [/*dy*]].
6157
Set reference point on the map for the image.
62-
box : bool or str
63-
[**+c**\ *clearances*][**+g**\ *fill*][**+i**\ [[*gap*/]\ *pen*]]\
64-
[**+p**\ [*pen*]][**+r**\ [*radius*]][**+s**\ [[*dx*/*dy*/][*shade*]]].
65-
If set to ``True``, draw a rectangular border around the image
66-
using :gmt-term:`MAP_FRAME_PEN`.
58+
box
59+
Draw a background box behind the image. If set to ``True``, a simple rectangular
60+
box is drawn using :gmt-term:`MAP_FRAME_PEN`. To customize the box appearance,
61+
pass a :class:`pygmt.params.Box` object to control style, fill, pen, and other
62+
box properties.
6763
bitcolor : str or list
6864
[*color*][**+b**\|\ **f**\|\ **t**].
6965
Change certain pixel values to another color or make them transparent.
@@ -82,7 +78,9 @@ def image(
8278
"""
8379
self._activate_figure()
8480

85-
aliasdict = AliasSystem().add_common(
81+
aliasdict = AliasSystem(
82+
F=Alias(box, name="box"),
83+
).add_common(
8684
J=projection,
8785
V=verbose,
8886
c=panel,

pygmt/src/inset.py

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,22 @@
55
import contextlib
66
from typing import Literal
77

8-
from pygmt.alias import AliasSystem
8+
from pygmt.alias import Alias, AliasSystem
99
from pygmt.clib import Session
1010
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
11+
from pygmt.params import Box
1112

1213
__doctest_skip__ = ["inset"]
1314

1415

1516
@fmt_docstring
1617
@contextlib.contextmanager
17-
@use_alias(
18-
D="position",
19-
F="box",
20-
M="margin",
21-
N="no_clip",
22-
R="region",
23-
)
18+
@use_alias(D="position", M="margin", N="no_clip", R="region")
2419
@kwargs_to_strings(D="sequence", M="sequence", R="sequence")
2520
def inset(
2621
self,
2722
projection=None,
23+
box: Box | bool = False,
2824
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
2925
| bool = False,
3026
**kwargs,
@@ -39,6 +35,7 @@ def inset(
3935
Full GMT docs at :gmt-docs:`inset.html`.
4036
4137
{aliases}
38+
- F = box
4239
- J = projection
4340
- V = verbose
4441
@@ -83,27 +80,11 @@ def inset(
8380
as *refpoint*, if **J** is used then *justify* defaults to the
8481
mirror opposite of *refpoint*. Specify inset box attributes via
8582
the ``box`` parameter [Default is outline only].
86-
box : str or bool
87-
[**+c**\ *clearances*][**+g**\ *fill*][**+i**\ [[*gap*/]\
88-
*pen*]][**+p**\ [*pen*]][**+r**\ [*radius*]][**+s**\
89-
[[*dx*/*dy*/][*shade*]]].
90-
If set to ``True``, draw a rectangular box around the map
91-
inset using the default pen; specify a different pen
92-
with **+p**\ *pen*. Add **+g**\ *fill* to fill the inset box
93-
[Default is no fill].
94-
Append **+c**\ *clearance* where *clearance* is either
95-
*gap*, *xgap*\ /\ *ygap*, or *lgap*\ /\ *rgap*\ /\ *bgap*\ /\
96-
*tgap* where these items are uniform, separate in x- and
97-
y-directions, or individual side spacings between map embellishment
98-
and border. Append **+i** to draw a secondary, inner border as well.
99-
We use a uniform *gap* between borders of 2p and the default pen
100-
unless other values are specified. Append **+r** to draw rounded
101-
rectangular borders instead, with a 6p corner radius. You
102-
can override this radius by appending another value. Append
103-
**+s** to draw an offset background shaded region. Here, *dx*/*dy*
104-
indicates the shift relative to the foreground frame [Default is
105-
``"4p/-4p"``] and *shade* sets the fill style to use for
106-
shading [Default is ``"gray50"``].
83+
box
84+
Draw a background box behind the inset. If set to ``True``, a simple rectangular
85+
box is drawn using :gmt-term:`MAP_FRAME_PEN`. To customize the box appearance,
86+
pass a :class:`pygmt.params.Box` object to control style, fill, pen, and other
87+
box properties.
10788
margin : float, str, or list
10889
This is clearance that is added around the inside of the inset.
10990
Plotting will take place within the inner region only. The margins
@@ -147,7 +128,9 @@ def inset(
147128
"""
148129
self._activate_figure()
149130

150-
aliasdict = AliasSystem().add_common(
131+
aliasdict = AliasSystem(
132+
F=Alias(box, name="box"),
133+
).add_common(
151134
J=projection,
152135
V=verbose,
153136
)

pygmt/src/legend.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import Literal
77

88
from pygmt._typing import PathLike
9-
from pygmt.alias import AliasSystem
9+
from pygmt.alias import Alias, AliasSystem
1010
from pygmt.clib import Session
1111
from pygmt.exceptions import GMTTypeError
1212
from pygmt.helpers import (
@@ -17,22 +17,18 @@
1717
kwargs_to_strings,
1818
use_alias,
1919
)
20+
from pygmt.params import Box
2021

2122

2223
@fmt_docstring
23-
@use_alias(
24-
R="region",
25-
D="position",
26-
F="box",
27-
p="perspective",
28-
)
24+
@use_alias(R="region", D="position", p="perspective")
2925
@kwargs_to_strings(R="sequence", p="sequence")
3026
def legend(
3127
self,
3228
spec: PathLike | io.StringIO | None = None,
3329
projection=None,
3430
position="JTR+jTR+o0.2c",
35-
box="+gwhite+p1p",
31+
box: Box | bool = False,
3632
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
3733
| bool = False,
3834
panel: int | tuple[int, int] | bool = False,
@@ -51,6 +47,7 @@ def legend(
5147
Full GMT docs at :gmt-docs:`legend.html`.
5248
5349
{aliases}
50+
- F = box
5451
- J = projection
5552
- V = verbose
5653
- c = panel
@@ -77,24 +74,23 @@ def legend(
7774
legend. By default, uses **JTR**\ **+jTR**\ **+o**\ 0.2c which
7875
places the legend at the top-right corner inside the map frame, with a
7976
0.2 cm offset.
80-
box : bool or str
81-
[**+c**\ *clearances*][**+g**\ *fill*][**+i**\ [[*gap*/]\ *pen*]]\
82-
[**+p**\ [*pen*]][**+r**\ [*radius*]][**+s**\ [[*dx*/*dy*/][*shade*]]].
83-
If set to ``True``, draw a rectangular border around the legend
84-
using :gmt-term:`MAP_FRAME_PEN`. By default, uses
85-
**+g**\ white\ **+p**\ 1p which draws a box around the legend using a
86-
1p black pen and adds a white background.
77+
box
78+
Draw a background box behind the legend. If set to ``True``, a simple
79+
rectangular box is drawn using :gmt-term:`MAP_FRAME_PEN`. To customize the box
80+
appearance, pass a :class:`pygmt.params.Box` object to control style, fill, pen,
81+
and other box properties.
8782
{verbose}
8883
{panel}
8984
{perspective}
9085
{transparency}
9186
"""
9287
self._activate_figure()
9388

89+
# Default position and box when not specified.
9490
if kwargs.get("D") is None:
9591
kwargs["D"] = position
96-
if kwargs.get("F") is None:
97-
kwargs["F"] = box
92+
if box is False and kwargs.get("F") is None:
93+
box = Box(pen="1p", fill="white") # Default box
9894

9995
kind = data_kind(spec)
10096
if kind not in {"empty", "file", "stringio"}:
@@ -104,7 +100,9 @@ def legend(
104100
type(spec), reason="Only one legend specification file is allowed."
105101
)
106102

107-
aliasdict = AliasSystem().add_common(
103+
aliasdict = AliasSystem(
104+
F=Alias(box, name="box"),
105+
).add_common(
108106
J=projection,
109107
V=verbose,
110108
c=panel,

0 commit comments

Comments
 (0)