Skip to content

Commit 0aea0b0

Browse files
Make clean border of shape
1 parent 945183b commit 0aea0b0

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

examples/gallery/embellishments/pygmt_logo.py

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,14 @@
3939
# -----------------------------------------------------------------------------
4040
color_concept = "color" # "color" | "bw"
4141
bg_concept = "dark" # "light" | "dark"
42-
shape = "hexagon" # "circle" | "hexagon"
42+
shape = "circle" # "circle" | "hexagon"
4343
wordmark = True # True | False
4444
orientation = "horizontal" # "horizontal" | "vertical"
45-
bg_transparent = True # True | False
45+
bg_transparent = False # True | False
4646

4747
angle_rot = 30 # degrees
4848
dpi_png = 720 # resolution of saved PNG image
4949

50-
5150
# -----------------------------------------------------------------------------
5251
# Define colors (-> can be discussed)
5352
# -----------------------------------------------------------------------------
@@ -70,7 +69,6 @@
7069
color_py = color_yellow
7170
color_gmt = "white"
7271

73-
7472
# -----------------------------------------------------------------------------
7573
# Not-changebale settings (-> need to extended)
7674
# -----------------------------------------------------------------------------
@@ -83,7 +81,6 @@
8381
pen_yellow = f"5p,{color_yellow}"
8482
pen_red = f"10p,{color_red}"
8583

86-
8784
# %%
8885

8986
# -----------------------------------------------------------------------------
@@ -102,10 +99,21 @@
10299
# .............................................................................
103100
match shape:
104101
case "circle":
105-
style = "c7.5c"
102+
diameter = 7.5
103+
diameter_add = 0.5
104+
symbol = "c"
106105
case "hexagon":
107-
style = "h8.6c"
108-
fig.plot(x=0, y=0, style=style, pen=f"15p,{color_blue}", fill=color_bg, no_clip=True)
106+
diameter = 8.6
107+
diameter_add = 0.6
108+
symbol = "h"
109+
fig.plot(
110+
x=0,
111+
y=0,
112+
style=f"{symbol}{diameter}c",
113+
pen=f"15p,{color_blue}",
114+
fill=color_bg,
115+
no_clip=True,
116+
)
109117

110118
# .............................................................................
111119
# yellow lines for compass
@@ -140,9 +148,9 @@
140148
# upper vertical red line
141149
# .............................................................................
142150
# space between red line and blue circle / hexagon
143-
fig.plot(x=[0, 0], y=[4.01, 3.0], pen=f"18p,{color_bg}")
151+
fig.plot(x=[0, 0], y=[4, 3.0], pen=f"18p,{color_bg}")
144152
# red line
145-
fig.plot(x=[0, 0], y=[4.00, 1.9], pen=f"12p,{color_red}")
153+
fig.plot(x=[0, 0], y=[4, 1.9], pen=f"12p,{color_red}")
146154

147155
# .............................................................................
148156
# letter M
@@ -172,16 +180,26 @@
172180
# arrow tail
173181
fig.plot(x=[0, 0], y=[-2, -3.57], pen=f"12p,{color_red}")
174182

183+
# margin around shape with slight overplotting for clean borders
184+
color_margin = color_bg
185+
if color_concept == "color" and bg_transparent and not wordmark:
186+
color_margin = "white"
187+
fig.plot(
188+
x=0,
189+
y=0,
190+
style=f"{symbol}{diameter + diameter_add}c",
191+
pen=f"1p,{color_margin}",
192+
no_clip=True,
193+
)
194+
175195
# .............................................................................
176196
# Save
177197
# .............................................................................
178198
fig.show()
179199
fig_name = f"pygmt_logo_{shape}_{color_concept}_{bg_concept}"
180200
fig.savefig(fname=f"{fig_name}.eps")
181-
# fig.savefig(fname=f"{fig_name}.png", dpi=dpi_png, transparent=True)
182201
print(fig_name)
183202

184-
185203
# %%
186204

187205
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -191,9 +209,7 @@
191209
pygmt.config(MAP_FRAME_PEN="cyan@100")
192210

193211
bg_alpha = 100 if bg_transparent is True else 0
194-
fig.basemap(
195-
region=region, projection=f"X{(size + 0.1) * 2}c", frame=f"+g{color_bg}@{bg_alpha}"
196-
)
212+
fig.basemap(region=region, projection=f"X{size * 2}c", frame=f"+g{color_bg}@{bg_alpha}")
197213

198214
fig.image(
199215
imagefile=f"{fig_name}.eps",
@@ -216,7 +232,6 @@
216232
fig.savefig(fname=f"{fig_name_rot}.{ext}", dpi=dpi_png, transparent=transparent)
217233
print(fig_name_rot)
218234

219-
220235
# %%
221236

222237
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -261,7 +276,6 @@
261276
print(fig_name_rot_text)
262277
Path.unlink(f"{fig_name_rot}.eps")
263278

264-
265279
# %%
266280
fig.show()
267281
Path.unlink(f"{fig_name}.eps")

0 commit comments

Comments
 (0)