From: <md...@us...> - 2007-09-12 17:25:26
|
Revision: 3839 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3839&view=rev Author: mdboom Date: 2007-09-12 10:25:19 -0700 (Wed, 12 Sep 2007) Log Message: ----------- Milestone -- simple_plot.py working with new affine framework (with the exception of dpi propagation) Modified Paths: -------------- branches/transforms/lib/matplotlib/affine.py branches/transforms/lib/matplotlib/axes.py branches/transforms/lib/matplotlib/figure.py branches/transforms/lib/matplotlib/lines.py Modified: branches/transforms/lib/matplotlib/affine.py =================================================================== --- branches/transforms/lib/matplotlib/affine.py 2007-09-12 15:41:22 UTC (rev 3838) +++ branches/transforms/lib/matplotlib/affine.py 2007-09-12 17:25:19 UTC (rev 3839) @@ -33,29 +33,29 @@ self._points = N.asarray(points, N.float_) self.track = False - # JDH: if you define a del method, the garbage collector won't - # destory cyclic references, so make sure you either manage these - # yourself or remove the __del__ after testing - def __del__(self): - if self.track: - print "Bbox::__del__" - #@staticmethod def unit(): - return Bbox([[0,0], [1,1]]) + return Bbox.from_lbrt(0., 0., 1., 1.) unit = staticmethod(unit) #@staticmethod def from_lbwh(left, bottom, width, height): - return Bbox([[left, bottom], [left + width, bottom + height]]) + return Bbox.from_lbrt(left, bottom, left + width, bottom + height) from_lbwh = staticmethod(from_lbwh) #@staticmethod - def from_lbrt(left, bottom, right, top): - return Bbox([[left, bottom], [right, top]]) + def from_lbrt(*args): + points = N.array(args, dtype=N.float_).reshape(2, 2) + return Bbox(points) from_lbrt = staticmethod(from_lbrt) - + def __cmp__(self, other): + # MGDTODO: Totally suboptimal + if isinstance(other, Bbox): + if (self._points == other._points).all(): + return 0 + return -1 + # JDH: the update method will update the box limits from the # existing limits and the new data; it appears here you are just # using the new data. We use an "ignore" flag to specify whether @@ -63,31 +63,18 @@ def update_from_data(self, x, y): self._points = N.array([[x.min(), y.min()], [x.max(), y.max()]], N.float_) self.invalidate() - if self.track: - print "Bbox::update_from_data", self._points def copy(self): - if self.track: - print "Bbox::copy" return Bbox(self._points.copy()) def __repr__(self): return 'Bbox(%s)' % repr(self._points) __str__ = __repr__ - def __cmp__(self, other): - # MGDTODO: Totally suboptimal - if isinstance(other, Bbox): - return (self._points == other._points).all() - return -1 - # MGDTODO: Probably a more efficient ways to do this... def _get_xmin(self): - if self.track: - print "Bbox::_get_xmin" return self._points[0, 0] def _set_xmin(self, val): - print "Bbox::_set_xmin" self._points[0, 0] = val self.invalidate() xmin = property(_get_xmin, _set_xmin) @@ -150,10 +137,10 @@ height = property(_get_height) def transformed(self, transform): - return Bbox(self.transform(self._points)) + return Bbox(transform(self._points)) def inverse_transformed(self, transform): - return Bbox(self.transform.inverted()(self._points)) + return Bbox(transform.inverted()(self._points)) def get_bounds(self): return (self.xmin, self.ymin, @@ -249,6 +236,14 @@ return "Affine2D(%s)" % repr(self._mtx) __str__ = __repr__ + def __cmp__(self, other): + # MGDTODO: We need to decide if we want deferred transforms + # to be equal to this one + if isinstance(other, Affine2D): + if (self.get_matrix() == other.get_matrix()).all(): + return 0 + return -1 + def _do_invalidation(self): result = self._inverted is None self._inverted = None @@ -380,10 +375,9 @@ if self._mtx is None: x_mtx = self._x.get_matrix() y_mtx = self._y.get_matrix() + # This works because we already know the transforms are + # separable self._mtx = N.vstack([x_mtx[0], y_mtx[1], [0.0, 0.0, 1.0]]) -# self._mtx = self.matrix_from_values( -# x_mtx[0,0], 0.0, 0.0, y_mtx[1,1], x_mtx[0,2], y_mtx[1,2]) - print "Blended", x_mtx, y_mtx, self._mtx def is_separable(self): return True @@ -429,8 +423,8 @@ def _make__mtx(self): if self._mtx is None: self._mtx = self._concat( - self._b.get_matrix(), - self._a.get_matrix()) + self._a.get_matrix(), + self._b.get_matrix()) def get_matrix(self): self._make__mtx() @@ -547,12 +541,70 @@ return interval[0] < val and interval[1] > val if __name__ == '__main__': + bbox = Bbox.from_lbrt(10., 15., 20., 25.) + assert bbox.xmin == 10 + assert bbox.ymin == 15 + assert bbox.xmax == 20 + assert bbox.ymax == 25 + + assert N.all(bbox.min == [10, 15]) + assert N.all(bbox.max == [20, 25]) + assert N.all(bbox.intervalx == (10, 20)) + assert N.all(bbox.intervaly == (15, 25)) + + assert bbox.width == 10 + assert bbox.height == 10 + + assert bbox.get_bounds() == (10, 15, 10, 10) + + bbox.intervalx = (11, 21) + bbox.intervaly = (16, 26) + + assert bbox.get_bounds() == (11, 16, 10, 10) + + bbox.xmin = 12 + bbox.ymin = 17 + bbox.xmax = 22 + bbox.ymax = 27 + + assert bbox.get_bounds() == (12, 17, 10, 10) + + bbox = Bbox.from_lbwh(10, 11, 12, 13) + assert bbox.get_bounds() == (10, 11, 12, 13) + + bbox_copy = bbox.copy() + assert bbox == bbox_copy + bbox_copy.max = (14, 15) + assert bbox.get_bounds() == (10, 11, 12, 13) + assert bbox_copy.get_bounds() == (10, 11, 4, 4) + bbox1 = Bbox([[10., 15.], [20., 25.]]) bbox2 = Bbox([[30., 35.], [40., 45.]]) trans = BboxTransform(bbox1, bbox2) - print trans(bbox1._points) + bbox3 = bbox1.transformed(trans) + assert bbox3 == bbox2 - bbox2.intervalx = 50, 55 - print trans(bbox1._points) + translation = Affine2D().translate(10, 20) + assert translation.to_values() == (1, 0, 0, 1, 10, 20) + scale = Affine2D().scale(10, 20) + assert scale.to_values() == (10, 0, 0, 20, 0, 0) + rotation = Affine2D().rotate_deg(30) + print rotation.to_values() == (0.86602540378443871, 0.49999999999999994, -0.49999999999999994, 0.86602540378443871, 0.0, 0.0) + points = N.array([[1,2],[3,4],[5,6],[7,8]], N.float_) + translated_points = translation(points) + assert (translated_points == [[11., 22.], [13., 24.], [15., 26.], [17., 28.]]).all() + scaled_points = scale(points) + print scaled_points + rotated_points = rotation(points) + print rotated_points + + tpoints1 = rotation(translation(scale(points))) + trans_sum = rotation + translation + scale + tpoints2 = trans_sum(points) + print tpoints1, tpoints2 + print tpoints1 == tpoints2 + # Need to do some sort of fuzzy comparison here? + # assert (tpoints1 == tpoints2).all() + __all__ = ['Transform', 'Affine2D'] Modified: branches/transforms/lib/matplotlib/axes.py =================================================================== --- branches/transforms/lib/matplotlib/axes.py 2007-09-12 15:41:22 UTC (rev 3838) +++ branches/transforms/lib/matplotlib/axes.py 2007-09-12 17:25:19 UTC (rev 3839) @@ -653,15 +653,12 @@ self.viewLim = Bbox.from_lbrt(left, bottom, right, top) self.dataLim = Bbox.unit() - self.dataLim.track = True self.transData = maffine.BboxTransform( self.viewLim, self.bbox) self.transAxes = maffine.BboxTransform( Bbox.unit(), self.bbox) - print "_set_lim_and_transforms", self.viewLim, self.transData, self.dataLim, self.transAxes, self.bbox - # MGDTODO # if self._sharex: # self.transData.set_funcx(self._sharex.transData.get_funcx()) @@ -697,7 +694,6 @@ # # Change values within self._position--don't replace it. # for num,val in zip(pos, self._position): # val.set(num) - print "set_position", self._position, pos self._position = pos # MGDTODO: side-effects if which in ('both', 'original'): @@ -1182,9 +1178,7 @@ #print type(x), type(y) # MGDTODO ## self.dataLim.update_numerix(x, y, -1) - print "update_datalim_numerix", self.dataLim, self.dataLim.update_from_data(x, y) - print self.dataLim def _get_verts_in_data_coords(self, trans, xys): if trans == self.transData: @@ -1245,8 +1239,6 @@ axis direction reversal that has already been done. """ # if image data only just use the datalim - print "autoscale_view", self._autoscaleon, scalex, scaley - if not self._autoscaleon: return if (tight or (len(self.images)>0 and len(self.lines)==0 and @@ -1274,7 +1266,7 @@ def draw(self, renderer=None, inframe=False): "Draw everything (plot lines, axes, labels)" - if renderer is None: + if renderer is None: renderer = self._cachedRenderer if renderer is None: @@ -1550,7 +1542,6 @@ xmin, xmax = maffine.nonsingular(xmin, xmax, increasing=False) self.viewLim.intervalx = (xmin, xmax) - print 'set_xlim', self.viewLim, xmin, xmax return xmin, xmax @@ -1654,7 +1645,6 @@ ACCEPTS: len(2) sequence of floats """ - print "set_ylim", ymin, ymax, emit if ymax is None and iterable(ymin): ymin,ymax = ymin @@ -1676,7 +1666,6 @@ ymin, ymax = maffine.nonsingular(ymin, ymax, increasing=False) self.viewLim.intervaly = (ymin, ymax) if emit: self.callbacks.process('ylim_changed', self) - print "set_ylim", self.viewLim return ymin, ymax Modified: branches/transforms/lib/matplotlib/figure.py =================================================================== --- branches/transforms/lib/matplotlib/figure.py 2007-09-12 15:41:22 UTC (rev 3838) +++ branches/transforms/lib/matplotlib/figure.py 2007-09-12 17:25:19 UTC (rev 3839) @@ -326,7 +326,6 @@ dpival = self.dpi self.bbox.max = w * dpival, h * dpival - print self.bbox # self.figwidth.set(w) MGDTODO # self.figheight.set(h) Modified: branches/transforms/lib/matplotlib/lines.py =================================================================== --- branches/transforms/lib/matplotlib/lines.py 2007-09-12 15:41:22 UTC (rev 3838) +++ branches/transforms/lib/matplotlib/lines.py 2007-09-12 17:25:19 UTC (rev 3839) @@ -389,7 +389,6 @@ def set_axes(self, ax): - print "set_axes" Artist.set_axes(self, ax) if ax.xaxis is not None: self._xcid = ax.xaxis.callbacks.connect('units', self.recache) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |