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

Skip to content

Commit 413a1be

Browse files
committed
updated fonts_demo and added kw version
svn path=/trunk/matplotlib/; revision=364
1 parent c108510 commit 413a1be

4 files changed

Lines changed: 112 additions & 29 deletions

File tree

examples/figimage_demo.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
rc('image', origin='lower')
99
figure(1, frameon=False)
1010
Z = arange(10000.0); Z.shape = 100,100
11-
Z[:,20:] = 1
11+
Z[:,50:] = 1
1212
jet() # sets the default
13-
im1 = figimage(Z, xo=50, yo=50) # you can also pass cmap=cm.jet as kwarg
13+
im1 = figimage(Z, xo=50, yo=0) # you can also pass cmap=cm.jet as kwarg
1414
im2 = figimage(Z, xo=100, yo=100, alpha=.8)
15-
gray() # overrides current and sets default
16-
#savefig('figimage_demo')
15+
#gray() # overrides current and sets default
16+
savefig('figimage_demo')
1717

1818
show()
1919

examples/fonts_demo.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env python
22

3-
from matplotlib.font_manager import fontManager, get_default_font, set_default_font
3+
from matplotlib.font_manager import fontManager, FontProperties
44
from matplotlib.matlab import *
55

66
subplot(111, axisbg='w')
77

8-
font0 = get_default_font()
9-
8+
font0 = FontProperties()
9+
alignment = {'horizontalalignment':'center', 'verticalalignment':'center'}
1010
### Show family options
1111

1212
family = ['serif', 'sans-serif', 'cursive', 'fantasy', 'monospace']
@@ -15,7 +15,7 @@
1515
font1.set_size('large')
1616

1717
t = text(-0.8, 0.9, 'family', fontproperties=font1,
18-
horizontalalignment='center', verticalalignment='center')
18+
**alignment)
1919

2020
yp = [0.7, 0.5, 0.3, 0.1, -0.1, -0.3, -0.5]
2121

@@ -25,84 +25,84 @@
2525
if k == 2:
2626
font.set_name('Script MT')
2727
t = text(-0.8, yp[k], family[k], fontproperties=font,
28-
horizontalalignment='center', verticalalignment='center')
28+
**alignment)
2929

3030
### Show style options
3131

3232
style = ['normal', 'italic', 'oblique']
3333

3434
t = text(-0.4, 0.9, 'style', fontproperties=font1,
35-
horizontalalignment='center', verticalalignment='center')
35+
**alignment)
3636

3737
for k in range(3):
3838
font = font0.copy()
3939
font.set_family('sans-serif')
4040
font.set_style(style[k])
4141
t = text(-0.4, yp[k], style[k], fontproperties=font,
42-
horizontalalignment='center', verticalalignment='center')
42+
**alignment)
4343

4444
### Show variant options
4545

4646
variant= ['normal', 'small-caps']
4747

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)
5050

5151
for k in range(1):
5252
font = font0.copy()
5353
font.set_family('serif')
5454
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)
5757

5858
### Show weight options
5959

6060
weight = ['light', 'normal', 'medium', 'semibold', 'bold', 'heavy', 'black']
6161

6262
t = text( 0.4, 0.9, 'weight', fontproperties=font1,
63-
horizontalalignment='center', verticalalignment='center')
63+
**alignment)
6464

6565
for k in range(7):
6666
font = font0.copy()
6767
font.set_weight(weight[k])
6868
t = text( 0.4, yp[k], weight[k], fontproperties=font,
69-
horizontalalignment='center', verticalalignment='center')
69+
**alignment)
7070

7171
### Show size options
7272

7373
size = ['xx-small', 'x-small', 'small', 'medium', 'large',
7474
'x-large', 'xx-large']
7575

7676
t = text( 0.8, 0.9, 'size', fontproperties=font1,
77-
horizontalalignment='center', verticalalignment='center')
77+
**alignment)
7878

7979
for k in range(7):
8080
font = font0.copy()
8181
font.set_size(size[k])
8282
t = text( 0.8, yp[k], size[k], fontproperties=font,
83-
horizontalalignment='center', verticalalignment='center')
83+
**alignment)
8484

8585
### Show bold italic
86-
86+
left = 0.1
8787
font = font0.copy()
8888
font.set_style('italic')
8989
font.set_weight('bold')
9090
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)
9393

9494
font = font0.copy()
9595
font.set_style('italic')
9696
font.set_weight('bold')
9797
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)
100100

101101
font = font0.copy()
102102
font.set_style('italic')
103103
font.set_weight('bold')
104104
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)
107107

108108
show()

examples/fonts_demo_kw.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env python
2+
"""
3+
Same as fonts_demo using kwargs
4+
"""
5+
from matplotlib.font_manager import fontManager, FontProperties
6+
from matplotlib.matlab import *
7+
8+
subplot(111, axisbg='w')
9+
alignment = {'horizontalalignment':'center', 'verticalalignment':'center'}
10+
### Show family options
11+
12+
family = ['serif', 'sans-serif', 'cursive', 'fantasy', 'monospace']
13+
14+
t = text(-0.8, 0.9, 'family', size='large', **alignment)
15+
16+
yp = [0.7, 0.5, 0.3, 0.1, -0.1, -0.3, -0.5]
17+
18+
for k in range(5):
19+
if k == 2:
20+
t = text(-0.8, yp[k], family[k], family=family[k],
21+
name='Script MT', **alignment)
22+
else:
23+
t = text(-0.8, yp[k], family[k], family=family[k], **alignment)
24+
25+
### Show style options
26+
27+
style = ['normal', 'italic', 'oblique']
28+
29+
t = text(-0.4, 0.9, 'style', **alignment)
30+
31+
for k in range(3):
32+
t = text(-0.4, yp[k], style[k], family='sans-serif', style=style[k],
33+
**alignment)
34+
35+
### Show variant options
36+
37+
variant= ['normal', 'small-caps']
38+
39+
t = text(0.2, 0.9, 'variant', **alignment)
40+
41+
for k in range(1):
42+
t = text( 0.2, yp[k], variant[k], family='serif', variant=variant[k],
43+
**alignment)
44+
45+
### Show weight options
46+
47+
weight = ['light', 'normal', 'medium', 'semibold', 'bold', 'heavy', 'black']
48+
49+
t = text( 0.4, 0.9, 'weight', **alignment)
50+
51+
for k in range(7):
52+
t = text( 0.4, yp[k], weight[k], weight=weight[k],
53+
**alignment)
54+
55+
### Show size options
56+
57+
size = ['xx-small', 'x-small', 'small', 'medium', 'large',
58+
'x-large', 'xx-large']
59+
60+
t = text( 0.8, 0.9, 'size', **alignment)
61+
62+
for k in range(7):
63+
t = text( 0.8, yp[k], size[k], size=size[k],
64+
**alignment)
65+
66+
left = 0.1
67+
### Show bold italic
68+
t = text(left, 0.1, 'bold italic', style='italic',
69+
weight='bold', size='x-small',
70+
**alignment)
71+
72+
t = text(left, 0.2, 'bold italic',
73+
style = 'italic', weight='bold', size='medium',
74+
**alignment)
75+
76+
t = text(left, 0.3, 'bold italic',
77+
style='italic', weight='bold', size='x-large',
78+
**alignment)
79+
80+
81+
show()

src/_backend_agg.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -881,15 +881,17 @@ RendererAgg::draw_image(const Py::Tuple& args) {
881881
throw Py::ValueError("origin must be upper|lower");
882882

883883
bool isUpper = origin=="upper";
884-
884+
std::cout << "agg says isupper " << origin << " " << isUpper << std::endl;
885+
885886

886887
//todo: handle x and y
887888
//agg::rect r(0, 0, image->colsOut, image->rowsOut);
888889
//rendererBase->copy_from(*image->rbufOut, &r, x, y);
889890
size_t ind=0;
890891
size_t thisx, thisy;
891-
size_t oy = height-y; //flipy
892-
if (isUpper) oy -= image->rowsOut; //start at top
892+
size_t oy = isUpper ? y : height-y;
893+
//if (isUpper) oy -= image->rowsOut; //start at top
894+
std::cout << "params " << height << " " << y << " " << oy << " " << image->rowsOut << std::endl;
893895
for (size_t j=0; j<image->rowsOut; j++) {
894896
for (size_t i=0; i<image->colsOut; i++) {
895897
thisx = i+x;

0 commit comments

Comments
 (0)