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

Skip to content

Commit b93f042

Browse files
author
Paul Barret
committed
An initial implementation of a fonts demo to excerise the font_manager class.
svn path=/trunk/matplotlib/; revision=242
1 parent 9e73bb2 commit b93f042

1 file changed

Lines changed: 106 additions & 0 deletions

File tree

examples/fonts_demo.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
2+
from matplotlib.font_manager import fontManager, get_default_font, set_default_font
3+
from matplotlib.matlab import *
4+
5+
subplot(111, axisbg='w')
6+
7+
font0 = get_default_font()
8+
9+
### Show family options
10+
11+
#family = ['serif', 'sans-serif', 'cursive', 'serif', 'monospace']
12+
family = ['serif', 'sans-serif', 'monospace']
13+
14+
font1 = font0.copy()
15+
font1.set_size('large')
16+
17+
t = text(-0.8, 0.9, 'family', fontproperties=font1,
18+
horizontalalignment='center', verticalalignment='center')
19+
20+
yp = [0.7, 0.5, 0.3, 0.1, -0.1, -0.3, -0.5]
21+
22+
for k in range(3):
23+
font = font0.copy()
24+
font.set_family(family[k])
25+
t = text(-0.8, yp[k], family[k], fontproperties=font,
26+
horizontalalignment='center', verticalalignment='center')
27+
28+
### Show style options
29+
30+
style = ['normal', 'italic', 'oblique']
31+
32+
t = text(-0.4, 0.9, 'style', fontproperties=font1,
33+
horizontalalignment='center', verticalalignment='center')
34+
35+
for k in range(2):
36+
font = font0.copy()
37+
font.set_family('sans-serif')
38+
font.set_style(style[k])
39+
t = text(-0.4, yp[k], style[k], fontproperties=font,
40+
horizontalalignment='center', verticalalignment='center')
41+
42+
### Show variant options
43+
44+
variant= ['normal', 'small-caps']
45+
46+
t = text(0.0, 0.9, 'variant', fontproperties=font1,
47+
horizontalalignment='center', verticalalignment='center')
48+
49+
for k in range(1):
50+
font = font0.copy()
51+
font.set_family('serif')
52+
font.set_variant(variant[k])
53+
t = text( 0.0, yp[k], variant[k], fontproperties=font,
54+
horizontalalignment='center', verticalalignment='center')
55+
56+
### Show weight options
57+
58+
weight = ['light', 'normal', 'medium', 'semibold', 'bold', 'heavy', 'black']
59+
60+
t = text( 0.4, 0.9, 'weight', fontproperties=font1,
61+
horizontalalignment='center', verticalalignment='center')
62+
63+
for k in range(7):
64+
font = font0.copy()
65+
font.set_weight(weight[k])
66+
t = text( 0.4, yp[k], weight[k], fontproperties=font,
67+
horizontalalignment='center', verticalalignment='center')
68+
69+
### Show size options
70+
71+
size = ['xx-small', 'x-small', 'small', 'medium', 'large',
72+
'x-large', 'xx-large']
73+
74+
t = text( 0.8, 0.9, 'size', fontproperties=font1,
75+
horizontalalignment='center', verticalalignment='center')
76+
77+
for k in range(7):
78+
font = font0.copy()
79+
font.set_size(size[k])
80+
t = text( 0.8, yp[k], size[k], fontproperties=font,
81+
horizontalalignment='center', verticalalignment='center')
82+
83+
### Show bold italic
84+
85+
font = font0.copy()
86+
font.set_style('italic')
87+
font.set_weight('bold')
88+
font.set_size('x-small')
89+
t = text(-0.2, 0.1, 'bold italic', fontproperties=font,
90+
horizontalalignment='center', verticalalignment='center')
91+
92+
font = font0.copy()
93+
font.set_style('italic')
94+
font.set_weight('bold')
95+
font.set_size('medium')
96+
t = text(-0.2, -0.1, 'bold italic', fontproperties=font,
97+
horizontalalignment='center', verticalalignment='center')
98+
99+
font = font0.copy()
100+
font.set_style('italic')
101+
font.set_weight('bold')
102+
font.set_size('x-large')
103+
t = text(-0.2, -0.3, 'bold italic', fontproperties=font,
104+
horizontalalignment='center', verticalalignment='center')
105+
106+
show()

0 commit comments

Comments
 (0)