From: <lee...@us...> - 2009-12-17 19:31:31
|
Revision: 8037 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8037&view=rev Author: leejjoon Date: 2009-12-17 19:31:21 +0000 (Thu, 17 Dec 2009) Log Message: ----------- draw_image api to use an arbitrary affine transform Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py trunk/matplotlib/lib/matplotlib/image.py Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2009-12-16 19:21:44 UTC (rev 8036) +++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2009-12-17 19:31:21 UTC (rev 8037) @@ -386,14 +386,15 @@ """ return True - def draw_image(self, gc, x, y, im, sx=None, sy=None): + def draw_image(self, gc, x, y, im, dx=None, dy=None, transform=None): """ Draw the Image instance into the current axes; x is the distance in pixels from the left hand side of the canvas and y is the distance from bottom - bbox is a matplotlib.transforms.BBox instance for clipping, or - None + dx, dy is the width and height of the image. If a transform + (which must be an affine transform) is given, x, y, dx, dy are + interpreted as the coordinate of the transform. """ im.flipud_out() @@ -406,13 +407,22 @@ imagecmd = "false 3 colorimage" hexlines = '\n'.join(self._hex_lines(bits)) - if sx is None: - sx = 1./self.image_magnification - if sy is None: - sy = 1./self.image_magnification - - xscale, yscale = (w*sx, h*sy) - + if dx is None: + xscale = w / self.image_magnification + else: + xscale = dx + + if dy is None: + yscale = h/self.image_magnification + else: + yscale = dy + + + if transform is None: + matrix = "1 0 0 1 0 0" + else: + matrix = " ".join(map(str, transform.to_values())) + figh = self.height*72 #print 'values', origin, flipud, figh, h, y @@ -431,6 +441,7 @@ #y = figh-(y+h) ps = """gsave %(clip)s +[%(matrix)s] concat %(x)s %(y)s translate %(xscale)s %(yscale)s scale /DataString %(w)s string def Modified: trunk/matplotlib/lib/matplotlib/image.py =================================================================== --- trunk/matplotlib/lib/matplotlib/image.py 2009-12-16 19:21:44 UTC (rev 8036) +++ trunk/matplotlib/lib/matplotlib/image.py 2009-12-17 19:31:21 UTC (rev 8037) @@ -144,7 +144,7 @@ sy = dyintv/viewlim.height numrows, numcols = A.shape[:2] if sx > 2: - x0 = (viewim.x0-xmin)/dxintv * numcols + x0 = (viewlim.x0-xmin)/dxintv * numcols ix0 = max(0, int(x0 - self._filterrad)) x1 = (viewlim.x1-xmin)/dxintv * numcols ix1 = min(numcols, int(x1 + self._filterrad)) @@ -170,7 +170,7 @@ ymin = ymin_old + iy0*dyintv/numrows ymax = ymin_old + iy1*dyintv/numrows dyintv = ymax - ymin - sy = dyintv/self.axes.viewLim.height + sy = dyintv/viewlim.height else: yslice = slice(0, numrows) @@ -203,7 +203,7 @@ return im, xmin, ymin, dxintv, dyintv, sx, sy - + def _draw_unsampled_image(self, renderer, gc): """ draw unsampled image. The renderer should support a draw_image method @@ -213,10 +213,6 @@ self._get_unsampled_image(self._A, self.get_extent(), self.axes.viewLim) if im is None: return # I'm not if this check is required. -JJL - - transData = self.axes.transData - xx1, yy1 = transData.transform_point((xmin, ymin)) - xx2, yy2 = transData.transform_point((xmin+dxintv, ymin+dyintv)) fc = self.axes.patch.get_facecolor() bg = mcolors.colorConverter.to_rgba(fc, 0) @@ -228,19 +224,23 @@ im.resize(numcols, numrows) # just to create im.bufOut that is required by backends. There may be better solution -JJL - sx = (xx2-xx1)/numcols - sy = (yy2-yy1)/numrows im._url = self.get_url() - renderer.draw_image(gc, xx1, yy1, im, sx, sy) - + trans = self.get_transform() #axes.transData + xx1, yy1 = trans.transform_non_affine((xmin, ymin)) + xx2, yy2 = trans.transform_non_affine((xmin+dxintv, ymin+dyintv)) + + renderer.draw_image(gc, xx1, yy1, im, xx2-xx1, yy2-yy1, + trans.get_affine()) + + def _check_unsampled_image(self, renderer): """ return True if the image is better to be drawn unsampled. The derived class needs to override it. """ return False - + @allow_rasterization def draw(self, renderer, *args, **kwargs): if not self.get_visible(): return This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |