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

Skip to content

Commit b15b6b6

Browse files
committed
fixed text with dash bug
svn path=/trunk/matplotlib/; revision=4698
1 parent 26d0732 commit b15b6b6

4 files changed

Lines changed: 58 additions & 27 deletions

File tree

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/cbook.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,10 @@ def recurse(obj, start, all, current_path):
962962
outstream.write("Examining: %r\n" % (obj,))
963963
recurse(obj, obj, { }, [])
964964

965+
966+
967+
968+
965969
if __name__=='__main__':
966970
assert( allequal([1,1,1]) )
967971
assert(not allequal([1,1,0]) )

lib/matplotlib/text.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,11 @@ def get_horizontalalignment(self):
387387
"Return the horizontal alignment as string"
388388
return self._horizontalalignment
389389

390+
391+
def _get_xy_display(self):
392+
'get the (possibly unit converted) transformed x,y in display coords'
393+
return self.get_transform().xy_tup((self._x, self._y))
394+
390395
def get_position(self):
391396
"Return x, y as tuple"
392397
x = float(self.convert_xunits(self._x))
@@ -770,7 +775,26 @@ def __init__(self,
770775

771776
#self.set_bbox(dict(pad=0))
772777

778+
def get_position(self):
779+
"Return x, y as tuple"
780+
x = float(self.convert_xunits(self._dashx))
781+
y = float(self.convert_yunits(self._dashy))
782+
return x, y
783+
784+
def get_prop_tup(self):
785+
"""
786+
Return a hashable tuple of properties
787+
788+
Not intended to be human readable, but useful for backends who
789+
want to cache derived information about text (eg layouts) and
790+
need to know if the text has changed
791+
"""
792+
props = [p for p in Text.get_prop_tup(self)]
793+
props.extend([self._x, self._y, self._dashlength, self._dashdirection, self._dashrotation, self._dashpad, self._dashpush])
794+
return tuple(props)
795+
773796
def draw(self, renderer):
797+
self.cached = dict()
774798
self.update_coords(renderer)
775799
Text.draw(self, renderer)
776800
if self.get_dashlength() > 0.0:
@@ -846,7 +870,11 @@ def update_coords(self, renderer):
846870
cwd *= 1+dashpad/npy.sqrt(npy.dot(cwd,cwd))
847871
cw = c2+(dashdirection*2-1)*cwd
848872

849-
self._x, self._y = transform.inverse_xy_tup(tuple(cw))
873+
874+
875+
newx, newy = transform.inverse_xy_tup(tuple(cw))
876+
877+
self._x, self._y = newx, newy
850878

851879
# Now set the window extent
852880
# I'm not at all sure this is the right way to do this.
@@ -930,9 +958,6 @@ def set_dashpush(self, dp):
930958
"""
931959
self._dashpush = dp
932960

933-
def get_position(self):
934-
"Return x, y as tuple"
935-
return self._dashx, self._dashy
936961

937962
def set_position(self, xy):
938963
"""

0 commit comments

Comments
 (0)