From: <jd...@us...> - 2007-12-11 21:18:19
|
Revision: 4698 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4698&view=rev Author: jdh2358 Date: 2007-12-11 13:17:59 -0800 (Tue, 11 Dec 2007) Log Message: ----------- fixed text with dash bug Modified Paths: -------------- trunk/matplotlib/examples/dashpointlabel.py trunk/matplotlib/examples/lasso_demo.py trunk/matplotlib/lib/matplotlib/cbook.py trunk/matplotlib/lib/matplotlib/text.py Modified: trunk/matplotlib/examples/dashpointlabel.py =================================================================== --- trunk/matplotlib/examples/dashpointlabel.py 2007-12-11 17:14:44 UTC (rev 4697) +++ trunk/matplotlib/examples/dashpointlabel.py 2007-12-11 21:17:59 UTC (rev 4698) @@ -1,4 +1,4 @@ -from matplotlib import pylab +import pylab DATA = ((1, 3), (2, 4), @@ -15,26 +15,27 @@ (1, 20, 30, 60, 10), ) -def test_dashpointlabel(save=False): - pylab.clf() - (x,y) = zip(*DATA) - pylab.plot(x, y, marker='o') - for i in xrange(len(DATA)): - (x,y) = DATA[i] - (dd, dl, r, dr, dp) = dash_style[i] - pylab.text(x, y, str((x,y)), withdash=True, - dashdirection=dd, - dashlength=dl, - rotation=r, - dashrotation=dr, - dashpush=dp, - ) - axis = pylab.gca() - axis.set_xlim((0.0, 5.0)) - axis.set_ylim((0.0, 5.0)) - if save: - pylab.savefig('dashpointlabel') - pylab.show() +fig = pylab.figure() +ax = fig.add_subplot(111) -if __name__ == '__main__': - test_dashpointlabel() + +(x,y) = zip(*DATA) +ax.plot(x, y, marker='o') +for i in xrange(len(DATA)): + (x,y) = DATA[i] + (dd, dl, r, dr, dp) = dash_style[i] + #print 'dashlen call', dl + t = ax.text(x, y, str((x,y)), withdash=True, + dashdirection=dd, + dashlength=dl, + rotation=r, + dashrotation=dr, + dashpush=dp, + ) + +ax.set_xlim((0.0, 5.0)) +ax.set_ylim((0.0, 5.0)) +#if save: +# pylab.savefig('dashpointlabel') +pylab.show() + Modified: trunk/matplotlib/examples/lasso_demo.py =================================================================== --- trunk/matplotlib/examples/lasso_demo.py 2007-12-11 17:14:44 UTC (rev 4697) +++ trunk/matplotlib/examples/lasso_demo.py 2007-12-11 21:17:59 UTC (rev 4698) @@ -59,6 +59,7 @@ self.canvas.draw_idle() self.canvas.widgetlock.release(self.lasso) del self.lasso + def onpress(self, event): if self.canvas.widgetlock.locked(): return if event.inaxes is None: return Modified: trunk/matplotlib/lib/matplotlib/cbook.py =================================================================== --- trunk/matplotlib/lib/matplotlib/cbook.py 2007-12-11 17:14:44 UTC (rev 4697) +++ trunk/matplotlib/lib/matplotlib/cbook.py 2007-12-11 21:17:59 UTC (rev 4698) @@ -962,6 +962,10 @@ outstream.write("Examining: %r\n" % (obj,)) recurse(obj, obj, { }, []) + + + + if __name__=='__main__': assert( allequal([1,1,1]) ) assert(not allequal([1,1,0]) ) Modified: trunk/matplotlib/lib/matplotlib/text.py =================================================================== --- trunk/matplotlib/lib/matplotlib/text.py 2007-12-11 17:14:44 UTC (rev 4697) +++ trunk/matplotlib/lib/matplotlib/text.py 2007-12-11 21:17:59 UTC (rev 4698) @@ -387,6 +387,11 @@ "Return the horizontal alignment as string" return self._horizontalalignment + + def _get_xy_display(self): + 'get the (possibly unit converted) transformed x,y in display coords' + return self.get_transform().xy_tup((self._x, self._y)) + def get_position(self): "Return x, y as tuple" x = float(self.convert_xunits(self._x)) @@ -770,7 +775,26 @@ #self.set_bbox(dict(pad=0)) + def get_position(self): + "Return x, y as tuple" + x = float(self.convert_xunits(self._dashx)) + y = float(self.convert_yunits(self._dashy)) + return x, y + + def get_prop_tup(self): + """ + Return a hashable tuple of properties + + Not intended to be human readable, but useful for backends who + want to cache derived information about text (eg layouts) and + need to know if the text has changed + """ + props = [p for p in Text.get_prop_tup(self)] + props.extend([self._x, self._y, self._dashlength, self._dashdirection, self._dashrotation, self._dashpad, self._dashpush]) + return tuple(props) + def draw(self, renderer): + self.cached = dict() self.update_coords(renderer) Text.draw(self, renderer) if self.get_dashlength() > 0.0: @@ -846,8 +870,12 @@ cwd *= 1+dashpad/npy.sqrt(npy.dot(cwd,cwd)) cw = c2+(dashdirection*2-1)*cwd - self._x, self._y = transform.inverse_xy_tup(tuple(cw)) + + newx, newy = transform.inverse_xy_tup(tuple(cw)) + + self._x, self._y = newx, newy + # Now set the window extent # I'm not at all sure this is the right way to do this. we = Text.get_window_extent(self, renderer=renderer) @@ -930,9 +958,6 @@ """ self._dashpush = dp - def get_position(self): - "Return x, y as tuple" - return self._dashx, self._dashy def set_position(self, xy): """ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |