Skip to content

Commit b7e1985

Browse files
authored
Figure.pygmtlogo: Improved positioning of horizontal wordmark for circular PyGMT logo (#4627)
1 parent 40fb536 commit b7e1985

4 files changed

Lines changed: 60 additions & 6 deletions

File tree

pygmt/src/pygmtlogo.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def _create_logo( # noqa: PLR0915
3434
size = 4
3535
proj = "x1c"
3636
region = {
37-
"horizontal": [-size, size * 8.0, -size, size],
37+
"horizontal": [-size, size * 7.0, -size, size],
3838
"vertical": [-size, size, -size * 1.75, size],
3939
"none": [-size, size, -size, size],
4040
}[wordmark]
@@ -79,12 +79,27 @@ def _create_logo( # noqa: PLR0915
7979
hex_factor = 1.1
8080

8181
# Define wordmark
82+
# See https://github.com/GenericMappingTools/pygmt/pull/4627#issuecomment-4437317011
83+
# for the rationale behind the magic values.
8284
font = "AvantGarde-Book"
85+
pheight = 0.739 # Height of letter "P"
86+
plsb = 0.076 # Left side bearing of letter "P"
87+
pstroke = 0.0735 # Stroke thickness of letter "P"
88+
8389
match wordmark:
8490
case "vertical":
85-
args_text_wm = {"x": 0, "y": -4.5, "justify": "CT", "font": f"2.4c,{font}"}
91+
args_wordmark = {"x": 0, "y": -4.5, "justify": "CT", "font": f"2.4c,{font}"}
8692
case "horizontal":
87-
args_text_wm = {"x": 4.5, "y": 0.8, "justify": "LM", "font": f"8c,{font}"}
93+
# The stroke width matches the outline thickness.
94+
# The left edge of "P" is aligned at y=size * 1.25.
95+
# Letters "PGMT" are placed vertically centered at y=0.
96+
fontsize = thick_shape / pstroke
97+
args_wordmark = {
98+
"x": size * 1.25 - plsb * fontsize,
99+
"y": -pheight / 2.0 * fontsize,
100+
"justify": "BL",
101+
"font": f"{fontsize}c,{font}",
102+
}
88103

89104
def _letter_g_coords():
90105
"""Coordinates for letter G."""
@@ -218,7 +233,7 @@ def _compass_lines():
218233

219234
# Add wordmark "PyGMT"
220235
if wordmark != "none":
221-
fig.text(text=f"@;{color_py};Py@;;@;{color_gmt};GMT@;;", **args_text_wm)
236+
fig.text(text=f"@;{color_py};Py@;;@;{color_gmt};GMT@;;", **args_wordmark)
222237

223238
# Helpful for implementing the logo; not included in the logo
224239
if debug:
@@ -237,6 +252,11 @@ def _compass_lines():
237252
fig.hlines(y=[r4, r5], xmin=-size_s, xmax=size_s, pen=pen, perspective=True)
238253
m_mid = (thick_gap + r4) / 2
239254
fig.vlines(x=[r4, m_mid], ymin=-size_s, ymax=size_s, pen=pen, perspective=True)
255+
# Lines for wordmark
256+
if wordmark == "horizontal":
257+
halfheight = pheight / 2.0 * fontsize
258+
fig.hlines(y=[-halfheight, halfheight], xmin=size, pen=pen)
259+
fig.vlines(x=[size * 1.25, size * 1.25 + pstroke * fontsize], pen=pen)
240260

241261
if figname:
242262
fig.savefig(fname=figname)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
outs:
2-
- md5: 8924c7d80afcc92df4e77e6856b553a4
3-
size: 336254
2+
- md5: 44a9a200fbac4c868b69cb1c13e6dfc5
3+
size: 320394
44
hash: md5
55
path: test_pygmtlogo_design_circle-horizontal.png
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
outs:
2+
- md5: 9715eb13bec45201818d701970a529c8
3+
size: 63949
4+
hash: md5
5+
path: test_pygmtlogo_wordmark_horizontal_circle.png

pygmt/tests/test_pygmtlogo.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,32 @@ def test_pygmtlogo_wordmark_none(shape):
4949
shape=shape,
5050
)
5151
return fig
52+
53+
54+
@pytest.mark.mpl_image_compare
55+
@pytest.mark.parametrize("shape", ["circle"])
56+
def test_pygmtlogo_wordmark_horizontal(shape):
57+
"""
58+
Test the PyGMT logo with a horizontal wordmark, including both light/dark themes,
59+
and colored/black-and-white versions.
60+
"""
61+
fig = Figure()
62+
fig.basemap(
63+
region=[-0.5, 8.0, -0.5, 10.0],
64+
projection="x1c",
65+
frame=Frame(fill="gray", axis=Axis(grid=0.5)),
66+
)
67+
for (x, y), theme, color in [
68+
((0, 8.5), "light", True),
69+
((0, 6), "dark", True),
70+
((0, 3.5), "light", False),
71+
((0, 1), "dark", False),
72+
]:
73+
fig.pygmtlogo(
74+
position=Position((x, y), anchor="ML", cstype="mapcoords"),
75+
theme=theme,
76+
color=color,
77+
shape=shape,
78+
wordmark="horizontal",
79+
)
80+
return fig

0 commit comments

Comments
 (0)