Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 38fbda6

Browse files
committed
Update fonts_demo
Print all text within figure and remove missing cursive text
1 parent f44b5a4 commit 38fbda6

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

examples/pylab_examples/fonts_demo.py

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,77 +14,75 @@
1414
alignment = {'horizontalalignment': 'center', 'verticalalignment': 'baseline'}
1515
# Show family options
1616

17-
family = ['serif', 'sans-serif', 'cursive', 'fantasy', 'monospace']
17+
families = ['serif', 'sans-serif', 'cursive', 'fantasy', 'monospace']
1818

1919
font1 = font0.copy()
2020
font1.set_size('large')
2121

2222
t = text(-0.8, 0.9, 'family', fontproperties=font1,
2323
**alignment)
2424

25-
yp = [0.7, 0.5, 0.3, 0.1, -0.1, -0.3, -0.5]
25+
yp = [0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2]
2626

27-
for k in range(5):
27+
for k, family in enumerate(families):
2828
font = font0.copy()
29-
font.set_family(family[k])
30-
if k == 2:
31-
font.set_name('Script MT')
32-
t = text(-0.8, yp[k], family[k], fontproperties=font,
29+
font.set_family(family)
30+
t = text(-0.8, yp[k], family, fontproperties=font,
3331
**alignment)
3432

3533
# Show style options
3634

37-
style = ['normal', 'italic', 'oblique']
35+
styles = ['normal', 'italic', 'oblique']
3836

3937
t = text(-0.4, 0.9, 'style', fontproperties=font1,
4038
**alignment)
4139

42-
for k in range(3):
40+
for k, style in enumerate(styles):
4341
font = font0.copy()
4442
font.set_family('sans-serif')
45-
font.set_style(style[k])
46-
t = text(-0.4, yp[k], style[k], fontproperties=font,
43+
font.set_style(style)
44+
t = text(-0.4, yp[k], style, fontproperties=font,
4745
**alignment)
4846

4947
# Show variant options
5048

51-
variant = ['normal', 'small-caps']
49+
variants = ['normal', 'small-caps']
5250

5351
t = text(0.0, 0.9, 'variant', fontproperties=font1,
5452
**alignment)
5553

56-
for k in range(2):
54+
for k, variant in enumerate(variants):
5755
font = font0.copy()
5856
font.set_family('serif')
59-
font.set_variant(variant[k])
60-
t = text(0.0, yp[k], variant[k], fontproperties=font,
57+
font.set_variant(variant)
58+
t = text(0.0, yp[k], variant, fontproperties=font,
6159
**alignment)
6260

6361
# Show weight options
6462

65-
weight = ['light', 'normal', 'medium', 'semibold', 'bold', 'heavy', 'black']
63+
weights = ['light', 'normal', 'medium', 'semibold', 'bold', 'heavy', 'black']
6664

6765
t = text(0.4, 0.9, 'weight', fontproperties=font1,
6866
**alignment)
6967

70-
for k in range(7):
68+
for k, weight in enumerate(weights):
7169
font = font0.copy()
72-
font.set_weight(weight[k])
73-
t = text(0.4, yp[k], weight[k], fontproperties=font,
70+
font.set_weight(weight)
71+
t = text(0.4, yp[k], weight, fontproperties=font,
7472
**alignment)
7573

7674
# Show size options
7775

78-
size = ['xx-small', 'x-small', 'small', 'medium', 'large',
79-
'x-large', 'xx-large']
76+
sizes = ['xx-small', 'x-small', 'small', 'medium', 'large',
77+
'x-large', 'xx-large']
8078

8179
t = text(0.8, 0.9, 'size', fontproperties=font1,
8280
**alignment)
8381

84-
for k in range(7):
82+
for k, size in enumerate(sizes):
8583
font = font0.copy()
86-
font.set_size(size[k])
87-
t = text(0.8, yp[k], size[k], fontproperties=font,
84+
font.set_size(size)
85+
t = text(0.8, yp[k], size, fontproperties=font,
8886
**alignment)
8987

9088
# Show bold italic
@@ -93,21 +91,21 @@
9391
font.set_style('italic')
9492
font.set_weight('bold')
9593
font.set_size('x-small')
96-
t = text(0, 0.1, 'bold italic', fontproperties=font,
94+
t = text(-0.4, 0.1, 'bold italic', fontproperties=font,
9795
**alignment)
9896

9997
font = font0.copy()
10098
font.set_style('italic')
10199
font.set_weight('bold')
102100
font.set_size('medium')
103-
t = text(0, 0.2, 'bold italic', fontproperties=font,
101+
t = text(-0.4, 0.2, 'bold italic', fontproperties=font,
104102
**alignment)
105103

106104
font = font0.copy()
107105
font.set_style('italic')
108106
font.set_weight('bold')
109107
font.set_size('x-large')
110-
t = text(0, 0.3, 'bold italic', fontproperties=font,
108+
t = text(-0.4, 0.3, 'bold italic', fontproperties=font,
111109
**alignment)
112110

113111
axis([-1, 1, 0, 1])

0 commit comments

Comments
 (0)