Skip to content

Commit ce7a3c4

Browse files
authored
Figure.pygmtlogo: Improve positioning of vertical wordmark for circular PyGMT logo (#4637)
1 parent 4067d55 commit ce7a3c4

4 files changed

Lines changed: 48 additions & 3 deletions

File tree

pygmt/src/pygmtlogo.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,19 @@ def _create_logo( # noqa: PLR0915
8585
pheight = 0.739 # Height of letter "P"
8686
plsb = 0.076 # Left side bearing of letter "P"
8787
pstroke = 0.0735 # Stroke thickness of letter "P"
88+
pygmtwidth = 3.262 # Full width of "PyGMT"
8889

8990
match wordmark:
9091
case "vertical":
91-
args_wordmark = {"x": 0, "y": -4.5, "justify": "CT", "font": f"2.4c,{font}"}
92+
# Ensure the same width for the visual logo and wordmark
93+
fontsize = size * 2.0 / pygmtwidth
94+
args_wordmark = {
95+
"x": -size - fontsize * plsb,
96+
"y": -size * 1.375, # Center of the wordmark.
97+
"justify": "ML",
98+
"font": f"{fontsize}c,{font}",
99+
"no_clip": True, # Needed because x<xmin.
100+
}
92101
case "horizontal":
93102
# The stroke width matches the outline thickness.
94103
# The left edge of "P" is aligned at y=size * 1.25.
@@ -257,6 +266,8 @@ def _compass_lines():
257266
halfheight = pheight / 2.0 * fontsize
258267
fig.hlines(y=[-halfheight, halfheight], xmin=size, pen=pen)
259268
fig.vlines(x=[size * 1.25, size * 1.25 + pstroke * fontsize], pen=pen)
269+
elif wordmark == "vertical":
270+
fig.hlines(y=-size * 1.375, pen=pen)
260271

261272
if figname:
262273
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: 5ee82660f20bc8424f3051af4f9fb9ac
3-
size: 173671
2+
- md5: 4b7c27283350dd435d7e5d3c94767a2c
3+
size: 174973
44
hash: md5
55
path: test_pygmtlogo_design_circle-vertical.png
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
outs:
2+
- md5: 3e001517210b78b2dfdd2c1fce8b104a
3+
size: 40772
4+
hash: md5
5+
path: test_pygmtlogo_wordmark_vertical_circle.png

pygmt/tests/test_pygmtlogo.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,32 @@ def test_pygmtlogo_wordmark_horizontal(shape):
7878
wordmark="horizontal",
7979
)
8080
return fig
81+
82+
83+
@pytest.mark.mpl_image_compare
84+
@pytest.mark.parametrize("shape", ["circle"])
85+
def test_pygmtlogo_wordmark_vertical(shape):
86+
"""
87+
Test the PyGMT logo with a vertical wordmark, including both light/dark themes,
88+
and colored/black-and-white versions.
89+
"""
90+
fig = Figure()
91+
fig.basemap(
92+
region=[-0.5, 5.0, -0.5, 5.5],
93+
projection="x1c",
94+
frame=Frame(fill="gray", axis=Axis(grid=0.5)),
95+
)
96+
for (x, y), theme, color in [
97+
((1.0, 4.0), "light", True),
98+
((3.5, 4.0), "dark", True),
99+
((1.0, 1.0), "light", False),
100+
((3.5, 1.0), "dark", False),
101+
]:
102+
fig.pygmtlogo(
103+
position=Position((x, y), anchor="CM", cstype="mapcoords"),
104+
theme=theme,
105+
color=color,
106+
shape=shape,
107+
wordmark="vertical",
108+
)
109+
return fig

0 commit comments

Comments
 (0)