Skip to content

Commit ae85b62

Browse files
QuLogicmeeseeksmachine
authored andcommitted
Backport PR #28836: MNT: Use __init__ parameters of font properties
1 parent e528a38 commit ae85b62

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

galleries/examples/text_labels_and_annotations/fonts_demo.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -21,43 +21,36 @@
2121
fig.text(0.1, 0.9, 'family', fontproperties=heading_font, **alignment)
2222
families = ['serif', 'sans-serif', 'cursive', 'fantasy', 'monospace']
2323
for k, family in enumerate(families):
24-
font = FontProperties()
25-
font.set_family(family)
24+
font = FontProperties(family=[family])
2625
fig.text(0.1, yp[k], family, fontproperties=font, **alignment)
2726

2827
# Show style options
2928
styles = ['normal', 'italic', 'oblique']
3029
fig.text(0.3, 0.9, 'style', fontproperties=heading_font, **alignment)
3130
for k, style in enumerate(styles):
32-
font = FontProperties()
33-
font.set_family('sans-serif')
34-
font.set_style(style)
31+
font = FontProperties(family='sans-serif', style=style)
3532
fig.text(0.3, yp[k], style, fontproperties=font, **alignment)
3633

3734
# Show variant options
3835
variants = ['normal', 'small-caps']
3936
fig.text(0.5, 0.9, 'variant', fontproperties=heading_font, **alignment)
4037
for k, variant in enumerate(variants):
41-
font = FontProperties()
42-
font.set_family('serif')
43-
font.set_variant(variant)
38+
font = FontProperties(family='serif', variant=variant)
4439
fig.text(0.5, yp[k], variant, fontproperties=font, **alignment)
4540

4641
# Show weight options
4742
weights = ['light', 'normal', 'medium', 'semibold', 'bold', 'heavy', 'black']
4843
fig.text(0.7, 0.9, 'weight', fontproperties=heading_font, **alignment)
4944
for k, weight in enumerate(weights):
50-
font = FontProperties()
51-
font.set_weight(weight)
45+
font = FontProperties(weight=weight)
5246
fig.text(0.7, yp[k], weight, fontproperties=font, **alignment)
5347

5448
# Show size options
5549
sizes = [
5650
'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large']
5751
fig.text(0.9, 0.9, 'size', fontproperties=heading_font, **alignment)
5852
for k, size in enumerate(sizes):
59-
font = FontProperties()
60-
font.set_size(size)
53+
font = FontProperties(size=size)
6154
fig.text(0.9, yp[k], size, fontproperties=font, **alignment)
6255

6356
# Show bold italic

galleries/users_explain/text/text_intro.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,7 @@
177177

178178
from matplotlib.font_manager import FontProperties
179179

180-
font = FontProperties()
181-
font.set_family('serif')
182-
font.set_name('Times New Roman')
183-
font.set_style('italic')
180+
font = FontProperties(family='Times New Roman', style='italic')
184181

185182
fig, ax = plt.subplots(figsize=(5, 3))
186183
fig.subplots_adjust(bottom=0.15, left=0.2)

0 commit comments

Comments
 (0)