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

Skip to content

Commit a43661e

Browse files
committed
Merged revisions 4689-4706 via svnmerge from
http://matplotlib.svn.sf.net/svnroot/matplotlib/trunk/matplotlib ........ r4697 | pkienzle | 2007-12-11 12:14:44 -0500 (Tue, 11 Dec 2007) | 1 line remove wx specific gui_repaint comment ........ r4698 | jdh2358 | 2007-12-11 16:17:59 -0500 (Tue, 11 Dec 2007) | 2 lines fixed text with dash bug ........ r4706 | mdboom | 2007-12-12 09:08:15 -0500 (Wed, 12 Dec 2007) | 2 lines Support alpha-blended text in the Agg and Svg backends. ........ svn path=/branches/transforms/; revision=4708
1 parent a679cb6 commit a43661e

File tree

8 files changed

+67
-42
lines changed

8 files changed

+67
-42
lines changed

examples/dashpointlabel.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from matplotlib import pylab
1+
import pylab
22

33
DATA = ((1, 3),
44
(2, 4),
@@ -15,26 +15,27 @@
1515
(1, 20, 30, 60, 10),
1616
)
1717

18-
def test_dashpointlabel(save=False):
19-
pylab.clf()
20-
(x,y) = zip(*DATA)
21-
pylab.plot(x, y, marker='o')
22-
for i in xrange(len(DATA)):
23-
(x,y) = DATA[i]
24-
(dd, dl, r, dr, dp) = dash_style[i]
25-
pylab.text(x, y, str((x,y)), withdash=True,
26-
dashdirection=dd,
27-
dashlength=dl,
28-
rotation=r,
29-
dashrotation=dr,
30-
dashpush=dp,
31-
)
32-
axis = pylab.gca()
33-
axis.set_xlim((0.0, 5.0))
34-
axis.set_ylim((0.0, 5.0))
35-
if save:
36-
pylab.savefig('dashpointlabel')
37-
pylab.show()
18+
fig = pylab.figure()
19+
ax = fig.add_subplot(111)
20+
21+
22+
(x,y) = zip(*DATA)
23+
ax.plot(x, y, marker='o')
24+
for i in xrange(len(DATA)):
25+
(x,y) = DATA[i]
26+
(dd, dl, r, dr, dp) = dash_style[i]
27+
#print 'dashlen call', dl
28+
t = ax.text(x, y, str((x,y)), withdash=True,
29+
dashdirection=dd,
30+
dashlength=dl,
31+
rotation=r,
32+
dashrotation=dr,
33+
dashpush=dp,
34+
)
35+
36+
ax.set_xlim((0.0, 5.0))
37+
ax.set_ylim((0.0, 5.0))
38+
#if save:
39+
# pylab.savefig('dashpointlabel')
40+
pylab.show()
3841

39-
if __name__ == '__main__':
40-
test_dashpointlabel()

examples/lasso_demo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def callback(self, verts):
5959
self.canvas.draw_idle()
6060
self.canvas.widgetlock.release(self.lasso)
6161
del self.lasso
62+
6263
def onpress(self, event):
6364
if self.canvas.widgetlock.locked(): return
6465
if event.inaxes is None: return

lib/matplotlib/backend_bases.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,6 @@ def onHilite(self, ev):
843843
a.set_facecolor('lightblue')
844844
else: self._active[a] = None
845845
self.draw_idle()
846-
#self.gui_repaint()
847846

848847
def pick(self, mouseevent):
849848
if not self.widgetlock.locked():

lib/matplotlib/backends/backend_svg.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath):
296296
color = rgb2hex(gc.get_rgb()[:3])
297297

298298
if rcParams['svg.embed_char_paths']:
299-
svg = ['<g style="fill: %s" transform="' % color]
299+
svg = ['<g style="fill: %s; opacity: %s" transform="' % (color, gc.get_alpha())]
300300
if angle != 0:
301301
svg.append('translate(%s,%s)rotate(%1.1f)' % (x,y,-angle))
302302
elif x != 0 or y != 0:
@@ -335,7 +335,8 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath):
335335
fontfamily = font.family_name
336336
fontstyle = prop.get_style()
337337

338-
style = 'font-size: %f; font-family: %s; font-style: %s; fill: %s;'%(fontsize, fontfamily,fontstyle, color)
338+
style = ('font-size: %f; font-family: %s; font-style: %s; fill: %s; opacity: %s' %
339+
(fontsize, fontfamily,fontstyle, color, gc.get_alpha()))
339340
if angle!=0:
340341
transform = 'transform="translate(%s,%s) rotate(%1.1f) translate(%s,%s)"' % (x,y,-angle,-x,-y)
341342
# Inkscape doesn't support rotate(angle x y)

lib/matplotlib/cbook.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
set = set
1212
except NameError:
1313
from sets import Set as set
14-
14+
1515
major, minor1, minor2, s, tmp = sys.version_info
1616

1717

@@ -974,9 +974,9 @@ class Grouper(object):
974974
.get().
975975
976976
The objects being joined must be hashable.
977-
977+
978978
For example:
979-
979+
980980
>>> g = grouper.Grouper()
981981
>>> g.join('a', 'b')
982982
>>> g.join('b', 'c')
@@ -989,15 +989,15 @@ class Grouper(object):
989989
True
990990
>>> g.joined('a', 'd')
991991
False
992-
"""
992+
"""
993993
def __init__(self, init=[]):
994994
mapping = self._mapping = {}
995995
for x in init:
996996
mapping[x] = [x]
997997

998998
def __contains__(self, item):
999999
return item in self._mapping
1000-
1000+
10011001
def join(self, a, *args):
10021002
"""
10031003
Join given arguments into the same set.
@@ -1045,7 +1045,7 @@ def get_siblings(self, a):
10451045
"""
10461046
return self._mapping.get(a, [a])
10471047

1048-
1048+
10491049
def simple_linear_interpolation(a, steps):
10501050
steps = npy.floor(steps)
10511051
new_length = ((len(a) - 1) * steps) + 1
@@ -1061,7 +1061,7 @@ def simple_linear_interpolation(a, steps):
10611061
for i in range(1, int(steps)):
10621062
result[i::steps] = delta * i + a0
10631063
result[steps::steps] = a1
1064-
1064+
10651065
return result
10661066

10671067
if __name__=='__main__':

lib/matplotlib/patches.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,6 @@ def iter_circle_intersect_on_line(x0, y0, x1, y1):
10061006
dx = x1 - x0
10071007
dy = y1 - y0
10081008
dr2 = dx*dx + dy*dy
1009-
dr = npy.sqrt(dr2)
10101009
D = x0*y1 - x1*y0
10111010
D2 = D*D
10121011
discrim = dr2 - D2
@@ -1017,7 +1016,9 @@ def iter_circle_intersect_on_line(x0, y0, x1, y1):
10171016
y = (-D*dx) / dr2
10181017
yield x, y
10191018
elif discrim > 0.0:
1020-
if dy < 0:
1019+
# The definition of "sign" here is different from
1020+
# npy.sign: we never want to get 0.0
1021+
if dy < 0.0:
10211022
sign_dy = -1.0
10221023
else:
10231024
sign_dy = 1.0
@@ -1057,10 +1058,10 @@ def iter_circle_intersect_on_line_seg(x0, y0, x1, y1):
10571058
x0, y0 = p0
10581059
x1, y1 = p1
10591060
for x, y in iter_circle_intersect_on_line_seg(x0, y0, x1, y1):
1060-
# Convert radians to angles
10611061
theta = npy.arccos(x)
10621062
if y < 0:
10631063
theta = TWOPI - theta
1064+
# Convert radians to angles
10641065
theta *= RAD2DEG
10651066
if theta > theta1 and theta < theta2:
10661067
thetas[theta] = None
@@ -1072,7 +1073,6 @@ def iter_circle_intersect_on_line_seg(x0, y0, x1, y1):
10721073
last_theta = theta1
10731074
theta1_rad = theta1 * DEG2RAD
10741075
inside = box_path.contains_point((npy.cos(theta1_rad), npy.sin(theta1_rad)))
1075-
10761076
for theta in thetas:
10771077
if inside:
10781078
self._path = Path.arc(last_theta, theta, 8)

lib/matplotlib/text.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,11 @@ def get_horizontalalignment(self):
368368
"Return the horizontal alignment as string"
369369
return self._horizontalalignment
370370

371+
372+
def _get_xy_display(self):
373+
'get the (possibly unit converted) transformed x,y in display coords'
374+
return self.get_transform().transform_point((self._x, self._y))
375+
371376
def get_position(self):
372377
"Return x, y as tuple"
373378
x = float(self.convert_xunits(self._x))
@@ -631,6 +636,8 @@ def set_fontproperties(self, fp):
631636
632637
ACCEPTS: a matplotlib.font_manager.FontProperties instance
633638
"""
639+
if is_string_like(fp):
640+
fp = FontProperties(fp)
634641
self._fontproperties = fp
635642

636643
artist.kwdocd['Text'] = artist.kwdoc(Text)
@@ -731,6 +738,24 @@ def __init__(self,
731738

732739
#self.set_bbox(dict(pad=0))
733740

741+
def get_position(self):
742+
"Return x, y as tuple"
743+
x = float(self.convert_xunits(self._dashx))
744+
y = float(self.convert_yunits(self._dashy))
745+
return x, y
746+
747+
def get_prop_tup(self):
748+
"""
749+
Return a hashable tuple of properties
750+
751+
Not intended to be human readable, but useful for backends who
752+
want to cache derived information about text (eg layouts) and
753+
need to know if the text has changed
754+
"""
755+
props = [p for p in Text.get_prop_tup(self)]
756+
props.extend([self._x, self._y, self._dashlength, self._dashdirection, self._dashrotation, self._dashpad, self._dashpush])
757+
return tuple(props)
758+
734759
def draw(self, renderer):
735760
self.update_coords(renderer)
736761
Text.draw(self, renderer)
@@ -808,7 +833,8 @@ def update_coords(self, renderer):
808833
cwd *= 1+dashpad/npy.sqrt(npy.dot(cwd,cwd))
809834
cw = c2+(dashdirection*2-1)*cwd
810835

811-
self._x, self._y = inverse.transform_point(tuple(cw))
836+
newx, newy = inverse.transform_point(tuple(cw))
837+
self._x, self._y = newx, newy
812838

813839
# Now set the window extent
814840
# I'm not at all sure this is the right way to do this.
@@ -892,9 +918,6 @@ def set_dashpush(self, dp):
892918
"""
893919
self._dashpush = dp
894920

895-
def get_position(self):
896-
"Return x, y as tuple"
897-
return self._dashx, self._dashy
898921

899922
def set_position(self, xy):
900923
"""

src/_backend_agg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ class font_to_rgba
625625

626626
do {
627627
*output_span = _color;
628-
output_span->a = input_span->v;
628+
output_span->a = ((unsigned int)_color.a * (unsigned int)input_span->v) >> 8;
629629
++output_span;
630630
++input_span;
631631
} while (--len);

0 commit comments

Comments
 (0)