|
1 | | -#!/usr/bin/env python |
2 | 1 | """ |
3 | 2 | Show how to set custom font properties. |
4 | 3 |
|
5 | 4 | For interactive users, you can also use kwargs to the text command, |
6 | 5 | which requires less typing. See examples/fonts_demo_kw.py |
7 | 6 | """ |
8 | 7 | from matplotlib.font_manager import FontProperties |
9 | | -from pylab import * |
| 8 | +import matplotlib.pyplot as plt |
10 | 9 |
|
11 | | -subplot(111, axisbg='w') |
| 10 | +plt.subplot(111, axisbg='w') |
12 | 11 |
|
13 | 12 | font0 = FontProperties() |
14 | 13 | alignment = {'horizontalalignment': 'center', 'verticalalignment': 'baseline'} |
|
19 | 18 | font1 = font0.copy() |
20 | 19 | font1.set_size('large') |
21 | 20 |
|
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) |
24 | 23 |
|
25 | 24 | yp = [0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2] |
26 | 25 |
|
27 | 26 | for k, family in enumerate(families): |
28 | 27 | font = font0.copy() |
29 | 28 | 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) |
32 | 31 |
|
33 | 32 | # Show style options |
34 | 33 |
|
35 | 34 | styles = ['normal', 'italic', 'oblique'] |
36 | 35 |
|
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) |
39 | 38 |
|
40 | 39 | for k, style in enumerate(styles): |
41 | 40 | font = font0.copy() |
42 | 41 | font.set_family('sans-serif') |
43 | 42 | 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) |
46 | 45 |
|
47 | 46 | # Show variant options |
48 | 47 |
|
49 | 48 | variants = ['normal', 'small-caps'] |
50 | 49 |
|
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) |
53 | 52 |
|
54 | 53 | for k, variant in enumerate(variants): |
55 | 54 | font = font0.copy() |
56 | 55 | font.set_family('serif') |
57 | 56 | 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) |
60 | 59 |
|
61 | 60 | # Show weight options |
62 | 61 |
|
63 | 62 | weights = ['light', 'normal', 'medium', 'semibold', 'bold', 'heavy', 'black'] |
64 | 63 |
|
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) |
67 | 66 |
|
68 | 67 | for k, weight in enumerate(weights): |
69 | 68 | font = font0.copy() |
70 | 69 | 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) |
73 | 72 |
|
74 | 73 | # Show size options |
75 | 74 |
|
76 | 75 | sizes = ['xx-small', 'x-small', 'small', 'medium', 'large', |
77 | 76 | 'x-large', 'xx-large'] |
78 | 77 |
|
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) |
81 | 80 |
|
82 | 81 | for k, size in enumerate(sizes): |
83 | 82 | font = font0.copy() |
84 | 83 | 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) |
87 | 86 |
|
88 | 87 | # Show bold italic |
89 | 88 |
|
90 | 89 | font = font0.copy() |
91 | 90 | font.set_style('italic') |
92 | 91 | font.set_weight('bold') |
93 | 92 | 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) |
96 | 95 |
|
97 | 96 | font = font0.copy() |
98 | 97 | font.set_style('italic') |
99 | 98 | font.set_weight('bold') |
100 | 99 | 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) |
103 | 102 |
|
104 | 103 | font = font0.copy() |
105 | 104 | font.set_style('italic') |
106 | 105 | font.set_weight('bold') |
107 | 106 | 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) |
110 | 109 |
|
111 | | -axis([-1, 1, 0, 1]) |
| 110 | +plt.axis([-1, 1, 0, 1]) |
112 | 111 |
|
113 | | -show() |
| 112 | +plt.show() |
0 commit comments