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

Skip to content

Commit c6f191f

Browse files
committed
Merge pull request #3801 from jenshnielsen/font_cleanup
DOC : Fonts demos improvements
2 parents ebde05f + c48f88d commit c6f191f

File tree

4 files changed

+48
-53
lines changed

4 files changed

+48
-53
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])

examples/pylab_examples/fonts_demo_kw.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,61 +12,57 @@
1212

1313
# Show family options
1414

15-
family = ['serif', 'sans-serif', 'cursive', 'fantasy', 'monospace']
15+
families = ['serif', 'sans-serif', 'cursive', 'fantasy', 'monospace']
1616

1717
t = text(-0.8, 0.9, 'family', size='large', **alignment)
1818

19-
yp = [0.7, 0.5, 0.3, 0.1, -0.1, -0.3, -0.5]
19+
yp = [0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2]
2020

21-
for k in range(5):
22-
if k == 2:
23-
t = text(-0.8, yp[k], family[k], family=family[k],
24-
name='Script MT', **alignment)
25-
else:
26-
t = text(-0.8, yp[k], family[k], family=family[k], **alignment)
21+
for k, family in enumerate(families):
22+
t = text(-0.8, yp[k], family, family=family, **alignment)
2723

2824
# Show style options
2925

30-
style = ['normal', 'italic', 'oblique']
26+
styles = ['normal', 'italic', 'oblique']
3127

3228
t = text(-0.4, 0.9, 'style', **alignment)
3329

34-
for k in range(3):
35-
t = text(-0.4, yp[k], style[k], family='sans-serif', style=style[k],
30+
for k, style in enumerate(styles):
31+
t = text(-0.4, yp[k], style, family='sans-serif', style=style,
3632
**alignment)
3733

3834
# Show variant options
3935

40-
variant = ['normal', 'small-caps']
36+
variants = ['normal', 'small-caps']
4137

4238
t = text(0.0, 0.9, 'variant', **alignment)
4339

44-
for k in range(2):
45-
t = text(0.0, yp[k], variant[k], family='serif', variant=variant[k],
40+
for k, variant in enumerate(variants):
41+
t = text(0.0, yp[k], variant, family='serif', variant=variant,
4642
**alignment)
4743

4844
# Show weight options
4945

50-
weight = ['light', 'normal', 'medium', 'semibold', 'bold', 'heavy', 'black']
46+
weights = ['light', 'normal', 'medium', 'semibold', 'bold', 'heavy', 'black']
5147

5248
t = text(0.4, 0.9, 'weight', **alignment)
5349

54-
for k in range(7):
55-
t = text(0.4, yp[k], weight[k], weight=weight[k],
50+
for k, weight in enumerate(weights):
51+
t = text(0.4, yp[k], weight, weight=weight,
5652
**alignment)
5753

5854
# Show size options
5955

60-
size = ['xx-small', 'x-small', 'small', 'medium', 'large',
61-
'x-large', 'xx-large']
56+
sizes = ['xx-small', 'x-small', 'small', 'medium', 'large',
57+
'x-large', 'xx-large']
6258

6359
t = text(0.8, 0.9, 'size', **alignment)
6460

65-
for k in range(7):
66-
t = text(0.8, yp[k], size[k], size=size[k],
61+
for k, size in enumerate(sizes):
62+
t = text(0.8, yp[k], size, size=size,
6763
**alignment)
6864

69-
x = 0
65+
x = -0.4
7066
# Show bold italic
7167
t = text(x, 0.1, 'bold italic', style='italic',
7268
weight='bold', size='x-small',

lib/matplotlib/rcsetup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,10 @@ def __call__(self, s):
541541
'Arial', 'Helvetica', 'Avant Garde', 'sans-serif'],
542542
validate_stringlist],
543543
'font.cursive': [['Apple Chancery', 'Textile', 'Zapf Chancery',
544-
'Sand', 'cursive'], validate_stringlist],
544+
'Sand', 'Script MT', 'cursive'], validate_stringlist],
545545
'font.fantasy': [['Comic Sans MS', 'Chicago', 'Charcoal', 'Impact'
546-
'Western', 'fantasy'], validate_stringlist],
546+
'Western', 'Humor Sans', 'fantasy'],
547+
validate_stringlist],
547548
'font.monospace': [['Bitstream Vera Sans Mono', 'DejaVu Sans Mono',
548549
'Andale Mono', 'Nimbus Mono L', 'Courier New',
549550
'Courier', 'Fixed', 'Terminal', 'monospace'],

matplotlibrc.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ backend : %(backend)s
149149
#font.size : 12.0
150150
#font.serif : Bitstream Vera Serif, New Century Schoolbook, Century Schoolbook L, Utopia, ITC Bookman, Bookman, Nimbus Roman No9 L, Times New Roman, Times, Palatino, Charter, serif
151151
#font.sans-serif : Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif
152-
#font.cursive : Apple Chancery, Textile, Zapf Chancery, Sand, cursive
153-
#font.fantasy : Comic Sans MS, Chicago, Charcoal, Impact, Western, fantasy
152+
#font.cursive : Apple Chancery, Textile, Zapf Chancery, Sand, Script MT, cursive
153+
#font.fantasy : Comic Sans MS, Chicago, Charcoal, Impact, Western, Humor Sans, fantasy
154154
#font.monospace : Bitstream Vera Sans Mono, Andale Mono, Nimbus Mono L, Courier New, Courier, Fixed, Terminal, monospace
155155

156156
### TEXT

0 commit comments

Comments
 (0)