Skip to content

Commit a00a0aa

Browse files
committed
Simplify some iterations in scripts
1 parent 3d7d3ff commit a00a0aa

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

scripts/fonts.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@
2020
}
2121

2222
text = "The quick brown fox jumps over the lazy dog"
23-
for i, variant in enumerate(variants.keys()):
24-
ax.text(1, y, text, size=9, va="center",
25-
font=pathlib.Path(variants[variant]).resolve())
23+
for i, (variant, file) in enumerate(variants.items()):
24+
ax.text(1, y, text, size=9, va="center", font=pathlib.Path(file).resolve())
2625

2726
ax.text(39, y, variant,
2827
color="0.25", va="center", ha="right",
@@ -53,12 +52,11 @@
5352
"Source Code Pro" : "monospace" }
5453

5554
text = "The quick brown fox jumps over the lazy dog"
56-
for i, family in enumerate(families):
55+
for i, (family, label) in enumerate(families.items()):
5756
ax.text(1, y, text,
5857
va="center", size=9, family=family, weight="regular")
5958

60-
ax.text(39, y,
61-
"%s" % (families[family]),
59+
ax.text(39, y, label,
6260
color="0.25", va="center", ha="right",
6361
size="small", family="Source Code Pro", weight=400)
6462
y += 1.65
@@ -81,7 +79,7 @@
8179
ax.text(1, y, text, size=9,
8280
va="center", family="Source Sans Pro", weight=weight)
8381

84-
ax.text(39, y, "%s (%d)" % (weight, weights[weight]),
82+
ax.text(39, y, f"{weight} ({weights[weight]:d})",
8583
color="0.25", va="center", ha="right",
8684
size="small", family="Source Code Pro", weight=400)
8785
y += 1.65
@@ -97,11 +95,11 @@
9795
"xx-large" : 1.728 }
9896

9997
text = "The quick brown fox"
100-
for i, size in enumerate(sizes.keys()):
98+
for i, (size, scaling) in enumerate(sizes.items()):
10199
ax.text(1, y, text, size=size,
102100
ha="left", va="center", family="Source Sans Pro", weight="light")
103101

104-
ax.text(39, y, "%s (%.2f)" % (size, sizes[size]),
102+
ax.text(39, y, f"{size} ({scaling:.2f})",
105103
color="0.25", va="center", ha="right",
106104
size="small", family="Source Code Pro", weight=400)
107105
y += 1.65* max(sizes[size], sizes["small"])

scripts/tip-hatched.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
x2, y2 = x1+1, np.random.randint(25, 75, 2)
1616

1717
ax.bar(x1, y1, color=color2)
18-
for i in range(len(x1)):
19-
plt.annotate("%d%%" % y1[i], (x1[i], y1[i]), xytext=(0, 1),
18+
for x, y in zip(x1, y1):
19+
plt.annotate(f"{y:d}%", (x, y), xytext=(0, 1),
2020
fontsize="x-small", color=color2,
2121
textcoords="offset points", va="bottom", ha="center")
2222

2323
ax.bar(x2, y2, color=color2, hatch="/" )
24-
for i in range(len(x2)):
25-
plt.annotate("%d%%" % y2[i], (x2[i], y2[i]), xytext=(0, 1),
24+
for x, y in zip(x2, y2):
25+
plt.annotate(f"{y:d}%", (x, y), xytext=(0, 1),
2626
fontsize="x-small", color=color2,
2727
textcoords="offset points", va="bottom", ha="center")
2828

0 commit comments

Comments
 (0)