Skip to content

Commit 9f907ea

Browse files
committed
Add the Box class for specifying the box parameter
1 parent ddfa5dc commit 9f907ea

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

pygmt/params/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""
2+
Classes for PyGMT common parameters.
3+
"""
4+
5+
from pygmt.params.box import Box

pygmt/params/box.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"""
2+
The box parameter.
3+
"""
4+
5+
from collections.abc import Sequence
6+
from dataclasses import dataclass
7+
from typing import ClassVar
8+
9+
from pygmt.alias import Alias
10+
from pygmt.params.base import BaseParam
11+
12+
13+
@dataclass(repr=False)
14+
class Box(BaseParam):
15+
"""
16+
Class for the box around GMT embellishments.
17+
18+
Attributes
19+
----------
20+
clearance
21+
Set clearances between the embellishment and the box border. Can be either a
22+
scalar value or a list of two/four values.
23+
24+
- a scalar value means a uniform clearance in all four directions.
25+
- a list of two values means separate clearances in x- and y- directions.
26+
- a list of four values means separate clearances for left/right/bottom/top.
27+
fill
28+
Fill for the box. None means no fill.
29+
30+
Examples
31+
--------
32+
>>> from pygmt.params import Box
33+
>>> str(Box(fill="red@20"))
34+
'+gred@20'
35+
>>> str(Box(clearance=(0.2, 0.2), fill="red@20", pen="blue"))
36+
'+c0.2/0.2+gred@20+pblue'
37+
>>> str(Box(clearance=(0.2, 0.2), pen="blue", radius=True))
38+
'+c0.2/0.2+pblue+r'
39+
>>> str(Box(clearance=(0.1, 0.2, 0.3, 0.4), pen="blue", radius="10p"))
40+
'+c0.1/0.2/0.3/0.4+pblue+r10p'
41+
>>> str(
42+
... Box(
43+
... clearance=0.2,
44+
... pen="blue",
45+
... radius="10p",
46+
... shading=("5p", "5p", "lightred"),
47+
... )
48+
... )
49+
'+c0.2+pblue+r10p+s5p/5p/lightred'
50+
>>> str(Box(clearance=0.2, innerborder=("2p", "1p,red"), pen="blue"))
51+
'+c0.2+i2p/1p,red+pblue'
52+
"""
53+
54+
clearance: float | str | Sequence[float | str] | None = None
55+
fill: str | None = None
56+
innerborder: str | Sequence | None = None
57+
pen: str | None = None
58+
radius: float | bool | None = False
59+
shading: str | Sequence | None = None
60+
61+
_aliases: ClassVar = [
62+
Alias("clearance", prefix="+c", separator="/"),
63+
Alias("fill", prefix="+g"),
64+
Alias("innerborder", prefix="+i", separator="/"),
65+
Alias("pen", prefix="+p"),
66+
Alias("radius", prefix="+r"),
67+
Alias("shading", prefix="+s", separator="/"),
68+
]

0 commit comments

Comments
 (0)