Skip to content

Commit 187a733

Browse files
committed
Alias offset(D) for text
1 parent 9e7a353 commit 187a733

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

pygmt/base_plotting.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,15 @@ def legend(self, spec=None, position="JTR+jTR+o0.2c", box="+gwhite+p1p", **kwarg
813813
lib.call_module("legend", arg_str)
814814

815815
@fmt_docstring
816-
@use_alias(R="region", J="projection", B="frame", C="clearance", G="fill", W="pen")
816+
@use_alias(
817+
R="region",
818+
J="projection",
819+
B="frame",
820+
C="clearance",
821+
D="offset",
822+
G="fill",
823+
W="pen",
824+
)
817825
@kwargs_to_strings(
818826
R="sequence",
819827
textfiles="sequence_space",
@@ -907,6 +915,16 @@ def text(
907915
Sets the shade or color used for filling the text box [Default is
908916
no fill].
909917
instead.
918+
offset : str
919+
``[j|J]dx[/dy][+v[pen]]``
920+
Offsets the text from the projected (x,y) point by dx,dy [0/0]. If
921+
dy is not specified then it is set equal to dx. Use offset='j' to
922+
offset the text away from the point instead (i.e., the text
923+
justification will determine the direction of the shift). Using
924+
offset='J' will shorten diagonal offsets at corners by sqrt(2).
925+
Optionally, append '+v' which will draw a line from the original
926+
point to the shifted point; append a pen to change the attributes
927+
for this line.
910928
pen : str
911929
Sets the pen used to draw a rectangle around the text string
912930
(see *clearance*) [Default is width = default, color = black,
Loading

pygmt/tests/test_text.py

+19
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,25 @@ def test_text_xy_with_position_fails(region, projection):
121121
)
122122

123123

124+
@pytest.mark.mpl_image_compare
125+
def test_text_position_offset_with_line(region):
126+
"""
127+
Print text at four corners (top left/right, bottom left/right) of map,
128+
offset by 0.5 cm, with a line drawn from the original to the shifted point.
129+
"""
130+
fig = Figure()
131+
for position in ("TL", "TR", "BL", "BR"):
132+
fig.text(
133+
region=region,
134+
projection="x1c",
135+
frame="a",
136+
position=position,
137+
text=position,
138+
offset="j0.5c+v",
139+
)
140+
return fig
141+
142+
124143
@pytest.mark.mpl_image_compare
125144
def test_text_angle_30(region, projection):
126145
"""

0 commit comments

Comments
 (0)