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

Skip to content

Commit ee33e78

Browse files
committed
Merge pull request #5115 from ericmjl/mep12-fonts_demo.py
mep12 on fonts_demo.py
2 parents dae480d + 42a1211 commit ee33e78

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

examples/pylab_examples/fonts_demo.py

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
#!/usr/bin/env python
21
"""
32
Show how to set custom font properties.
43
54
For interactive users, you can also use kwargs to the text command,
65
which requires less typing. See examples/fonts_demo_kw.py
76
"""
87
from matplotlib.font_manager import FontProperties
9-
from pylab import *
8+
import matplotlib.pyplot as plt
109

11-
subplot(111, axisbg='w')
10+
plt.subplot(111, axisbg='w')
1211

1312
font0 = FontProperties()
1413
alignment = {'horizontalalignment': 'center', 'verticalalignment': 'baseline'}
@@ -19,95 +18,95 @@
1918
font1 = font0.copy()
2019
font1.set_size('large')
2120

22-
t = text(-0.8, 0.9, 'family', fontproperties=font1,
23-
**alignment)
21+
t = plt.text(-0.8, 0.9, 'family', fontproperties=font1,
22+
**alignment)
2423

2524
yp = [0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2]
2625

2726
for k, family in enumerate(families):
2827
font = font0.copy()
2928
font.set_family(family)
30-
t = text(-0.8, yp[k], family, fontproperties=font,
31-
**alignment)
29+
t = plt.text(-0.8, yp[k], family, fontproperties=font,
30+
**alignment)
3231

3332
# Show style options
3433

3534
styles = ['normal', 'italic', 'oblique']
3635

37-
t = text(-0.4, 0.9, 'style', fontproperties=font1,
38-
**alignment)
36+
t = plt.text(-0.4, 0.9, 'style', fontproperties=font1,
37+
**alignment)
3938

4039
for k, style in enumerate(styles):
4140
font = font0.copy()
4241
font.set_family('sans-serif')
4342
font.set_style(style)
44-
t = text(-0.4, yp[k], style, fontproperties=font,
45-
**alignment)
43+
t = plt.text(-0.4, yp[k], style, fontproperties=font,
44+
**alignment)
4645

4746
# Show variant options
4847

4948
variants = ['normal', 'small-caps']
5049

51-
t = text(0.0, 0.9, 'variant', fontproperties=font1,
52-
**alignment)
50+
t = plt.text(0.0, 0.9, 'variant', fontproperties=font1,
51+
**alignment)
5352

5453
for k, variant in enumerate(variants):
5554
font = font0.copy()
5655
font.set_family('serif')
5756
font.set_variant(variant)
58-
t = text(0.0, yp[k], variant, fontproperties=font,
59-
**alignment)
57+
t = plt.text(0.0, yp[k], variant, fontproperties=font,
58+
**alignment)
6059

6160
# Show weight options
6261

6362
weights = ['light', 'normal', 'medium', 'semibold', 'bold', 'heavy', 'black']
6463

65-
t = text(0.4, 0.9, 'weight', fontproperties=font1,
66-
**alignment)
64+
t = plt.text(0.4, 0.9, 'weight', fontproperties=font1,
65+
**alignment)
6766

6867
for k, weight in enumerate(weights):
6968
font = font0.copy()
7069
font.set_weight(weight)
71-
t = text(0.4, yp[k], weight, fontproperties=font,
72-
**alignment)
70+
t = plt.text(0.4, yp[k], weight, fontproperties=font,
71+
**alignment)
7372

7473
# Show size options
7574

7675
sizes = ['xx-small', 'x-small', 'small', 'medium', 'large',
7776
'x-large', 'xx-large']
7877

79-
t = text(0.8, 0.9, 'size', fontproperties=font1,
80-
**alignment)
78+
t = plt.text(0.8, 0.9, 'size', fontproperties=font1,
79+
**alignment)
8180

8281
for k, size in enumerate(sizes):
8382
font = font0.copy()
8483
font.set_size(size)
85-
t = text(0.8, yp[k], size, fontproperties=font,
86-
**alignment)
84+
t = plt.text(0.8, yp[k], size, fontproperties=font,
85+
**alignment)
8786

8887
# Show bold italic
8988

9089
font = font0.copy()
9190
font.set_style('italic')
9291
font.set_weight('bold')
9392
font.set_size('x-small')
94-
t = text(-0.4, 0.1, 'bold italic', fontproperties=font,
95-
**alignment)
93+
t = plt.text(-0.4, 0.1, 'bold italic', fontproperties=font,
94+
**alignment)
9695

9796
font = font0.copy()
9897
font.set_style('italic')
9998
font.set_weight('bold')
10099
font.set_size('medium')
101-
t = text(-0.4, 0.2, 'bold italic', fontproperties=font,
102-
**alignment)
100+
t = plt.text(-0.4, 0.2, 'bold italic', fontproperties=font,
101+
**alignment)
103102

104103
font = font0.copy()
105104
font.set_style('italic')
106105
font.set_weight('bold')
107106
font.set_size('x-large')
108-
t = text(-0.4, 0.3, 'bold italic', fontproperties=font,
109-
**alignment)
107+
t = plt.text(-0.4, 0.3, 'bold italic', fontproperties=font,
108+
**alignment)
110109

111-
axis([-1, 1, 0, 1])
110+
plt.axis([-1, 1, 0, 1])
112111

113-
show()
112+
plt.show()

0 commit comments

Comments
 (0)