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