SourceForge logo
SourceForge logo
Menu

matplotlib-checkins

From: <pki...@us...> - 2008年07月26日 19:17:07
Revision: 5888
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5888&view=rev
Author: pkienzle
Date: 2008年07月26日 19:17:05 +0000 (2008年7月26日)
Log Message:
-----------
Fix contains method for inverted image axes
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/image.py
Modified: trunk/matplotlib/lib/matplotlib/image.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/image.py	2008年07月26日 18:42:22 UTC (rev 5887)
+++ trunk/matplotlib/lib/matplotlib/image.py	2008年07月26日 19:17:05 UTC (rev 5888)
@@ -50,6 +50,9 @@
 
 interpnames = _interpd.keys()
 
+ def __str__(self):
+ return "AxesImage(%g,%g;%gx%g)" % tuple(self.axes.bbox.bounds)
+
 def __init__(self, ax,
 cmap = None,
 norm = None,
@@ -243,11 +246,15 @@
 # collection on nonlinear transformed coordinates.
 # TODO: consider returning image coordinates (shouldn't
 # be too difficult given that the image is rectilinear
+ x, y = mouseevent.xdata, mouseevent.ydata
 xmin, xmax, ymin, ymax = self.get_extent()
- xdata, ydata = mouseevent.xdata, mouseevent.ydata
- #print xdata, ydata, xmin, xmax, ymin, ymax
- if xdata is not None and ydata is not None:
- inside = xdata>=xmin and xdata<=xmax and ydata>=ymin and ydata<=ymax
+ if xmin > xmax:
+ xmin,xmax = xmax,xmin
+ if ymin > ymax:
+ ymin,ymax = ymax,ymin
+ #print x, y, xmin, xmax, ymin, ymax
+ if x is not None and y is not None:
+ inside = x>=xmin and x<=xmax and y>=ymin and y<=ymax
 else:
 inside = False
 
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <md...@us...> - 2008年10月20日 14:16:11
Revision: 6283
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6283&view=rev
Author: mdboom
Date: 2008年10月20日 14:16:05 +0000 (2008年10月20日)
Log Message:
-----------
[ 2173204 ] implot leaves environment unstable after bad image data
Report errors about invalid data sooner when using imshow.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/image.py
Modified: trunk/matplotlib/lib/matplotlib/image.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/image.py	2008年10月20日 14:09:30 UTC (rev 6282)
+++ trunk/matplotlib/lib/matplotlib/image.py	2008年10月20日 14:16:05 UTC (rev 6283)
@@ -285,6 +285,13 @@
 else:
 self._A = np.asarray(A) # assume array
 
+ if self._A.dtype != np.uint8 and not np.can_cast(self._A.dtype, np.float):
+ raise TypeError("Image data can not convert to float")
+
+ if (self._A.ndim not in (2, 3) or
+ (self._A.ndim == 3 and self._A.shape[-1] not in (3, 4))):
+ raise TypeError("Invalid dimensions for image data")
+
 self._imcache =None
 self._rgbacache = None
 self._oldxslice = None
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <ry...@us...> - 2009年02月12日 21:00:00
Revision: 6908
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6908&view=rev
Author: ryanmay
Date: 2009年02月12日 20:59:53 +0000 (2009年2月12日)
Log Message:
-----------
Update AxesImage for independent autoscaling of x and y axes.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/image.py
Modified: trunk/matplotlib/lib/matplotlib/image.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/image.py	2009年02月12日 20:06:50 UTC (rev 6907)
+++ trunk/matplotlib/lib/matplotlib/image.py	2009年02月12日 20:59:53 UTC (rev 6908)
@@ -317,8 +317,9 @@
 xmin, xmax, ymin, ymax = extent
 corners = (xmin, ymin), (xmax, ymax)
 self.axes.update_datalim(corners)
- if self.axes._autoscaleon:
+ if self.axes._autoscaleXon:
 self.axes.set_xlim((xmin, xmax))
+ if self.axes._autoscaleYon:
 self.axes.set_ylim((ymin, ymax))
 
 def get_interpolation(self):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <lee...@us...> - 2009年08月09日 19:25:56
Revision: 7439
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7439&view=rev
Author: leejjoon
Date: 2009年08月09日 19:25:49 +0000 (2009年8月09日)
Log Message:
-----------
reorganization of AxesImage and BboxImage
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/image.py
Modified: trunk/matplotlib/lib/matplotlib/image.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/image.py	2009年08月09日 18:50:15 UTC (rev 7438)
+++ trunk/matplotlib/lib/matplotlib/image.py	2009年08月09日 19:25:49 UTC (rev 7439)
@@ -26,7 +26,7 @@
 
 from matplotlib.transforms import BboxBase
 
-class AxesImage(martist.Artist, cm.ScalarMappable):
+class _AxesImageBase(martist.Artist, cm.ScalarMappable):
 zorder = 1
 # map interpolation strings to module constants
 _interpd = {
@@ -62,7 +62,6 @@
 norm = None,
 interpolation=None,
 origin=None,
- extent=None,
 filternorm=1,
 filterrad=4.0,
 resample = False,
@@ -87,7 +86,6 @@
 
 if origin is None: origin = rcParams['image.origin']
 self.origin = origin
- self._extent = extent
 self.set_filternorm(filternorm)
 self.set_filterrad(filterrad)
 self._filterrad = filterrad
@@ -126,108 +124,9 @@
 self._rgbacache = None
 cm.ScalarMappable.changed(self)
 
-
 def make_image(self, magnification=1.0):
- if self._A is None:
- raise RuntimeError('You must first set the image array or the image attribute')
+ raise RuntimeError('The make_image method must be overridden.')
 
- xmin, xmax, ymin, ymax = self.get_extent()
- dxintv = xmax-xmin
- dyintv = ymax-ymin
-
- # the viewport scale factor
- sx = dxintv/self.axes.viewLim.width
- sy = dyintv/self.axes.viewLim.height
- numrows, numcols = self._A.shape[:2]
- if sx > 2:
- x0 = (self.axes.viewLim.x0-xmin)/dxintv * numcols
- ix0 = max(0, int(x0 - self._filterrad))
- x1 = (self.axes.viewLim.x1-xmin)/dxintv * numcols
- ix1 = min(numcols, int(x1 + self._filterrad))
- xslice = slice(ix0, ix1)
- xmin_old = xmin
- xmin = xmin_old + ix0*dxintv/numcols
- xmax = xmin_old + ix1*dxintv/numcols
- dxintv = xmax - xmin
- sx = dxintv/self.axes.viewLim.width
- else:
- xslice = slice(0, numcols)
-
- if sy > 2:
- y0 = (self.axes.viewLim.y0-ymin)/dyintv * numrows
- iy0 = max(0, int(y0 - self._filterrad))
- y1 = (self.axes.viewLim.y1-ymin)/dyintv * numrows
- iy1 = min(numrows, int(y1 + self._filterrad))
- if self.origin == 'upper':
- yslice = slice(numrows-iy1, numrows-iy0)
- else:
- yslice = slice(iy0, iy1)
- ymin_old = ymin
- ymin = ymin_old + iy0*dyintv/numrows
- ymax = ymin_old + iy1*dyintv/numrows
- dyintv = ymax - ymin
- sy = dyintv/self.axes.viewLim.height
- else:
- yslice = slice(0, numrows)
-
- if xslice != self._oldxslice or yslice != self._oldyslice:
- self._imcache = None
- self._oldxslice = xslice
- self._oldyslice = yslice
-
- if self._imcache is None:
- if self._A.dtype == np.uint8 and len(self._A.shape) == 3:
- im = _image.frombyte(self._A[yslice,xslice,:], 0)
- im.is_grayscale = False
- else:
- if self._rgbacache is None:
- x = self.to_rgba(self._A, self._alpha)
- self._rgbacache = x
- else:
- x = self._rgbacache
- im = _image.fromarray(x[yslice,xslice], 0)
- if len(self._A.shape) == 2:
- im.is_grayscale = self.cmap.is_gray()
- else:
- im.is_grayscale = False
- self._imcache = im
-
- if self.origin=='upper':
- im.flipud_in()
- else:
- im = self._imcache
-
- fc = self.axes.patch.get_facecolor()
- bg = mcolors.colorConverter.to_rgba(fc, 0)
- im.set_bg( *bg)
-
- # image input dimensions
- im.reset_matrix()
- numrows, numcols = im.get_size()
-
- im.set_interpolation(self._interpd[self._interpolation])
-
- im.set_resample(self._resample)
-
- # the viewport translation
- tx = (xmin-self.axes.viewLim.x0)/dxintv * numcols
- ty = (ymin-self.axes.viewLim.y0)/dyintv * numrows
-
- l, b, r, t = self.axes.bbox.extents
- widthDisplay = (round(r) + 0.5) - (round(l) - 0.5)
- heightDisplay = (round(t) + 0.5) - (round(b) - 0.5)
- widthDisplay *= magnification
- heightDisplay *= magnification
- im.apply_translation(tx, ty)
-
- # resize viewport to display
- rx = widthDisplay / numcols
- ry = heightDisplay / numrows
- im.apply_scaling(rx*sx, ry*sy)
- im.resize(int(widthDisplay+0.5), int(heightDisplay+0.5),
- norm=self._filternorm, radius=self._filterrad)
- return im
-
 @allow_rasterization
 def draw(self, renderer, *args, **kwargs):
 if not self.get_visible(): return
@@ -314,20 +213,6 @@
 
 
 
- def set_extent(self, extent):
- """
- extent is data axes (left, right, bottom, top) for making image plots
- """
- self._extent = extent
-
- xmin, xmax, ymin, ymax = extent
- corners = (xmin, ymin), (xmax, ymax)
- self.axes.update_datalim(corners)
- if self.axes._autoscaleXon:
- self.axes.set_xlim((xmin, xmax))
- if self.axes._autoscaleYon:
- self.axes.set_ylim((ymin, ymax))
-
 def get_interpolation(self):
 """
 Return the interpolation method the image uses when resizing.
@@ -367,19 +252,6 @@
 'return the image resample boolean'
 return self._resample
 
- def get_extent(self):
- 'get the image extent: left, right, bottom, top'
- if self._extent is not None:
- return self._extent
- else:
- sz = self.get_size()
- #print 'sz', sz
- numrows, numcols = sz
- if self.origin == 'upper':
- return (-0.5, numcols-0.5, numrows-0.5, -0.5)
- else:
- return (-0.5, numcols-0.5, -0.5, numrows-0.5)
-
 def set_filternorm(self, filternorm):
 """
 Set whether the resize filter norms the weights -- see
@@ -412,6 +284,182 @@
 return self._filterrad
 
 
+
+class AxesImage(_AxesImageBase):
+ def __str__(self):
+ return "AxesImage(%g,%g;%gx%g)" % tuple(self.axes.bbox.bounds)
+
+ def __init__(self, ax,
+ cmap = None,
+ norm = None,
+ interpolation=None,
+ origin=None,
+ extent=None,
+ filternorm=1,
+ filterrad=4.0,
+ resample = False,
+ **kwargs
+ ):
+
+ """
+ interpolation and cmap default to their rc settings
+
+ cmap is a colors.Colormap instance
+ norm is a colors.Normalize instance to map luminance to 0-1
+
+ extent is data axes (left, right, bottom, top) for making image plots
+ registered with data plots. Default is to label the pixel
+ centers with the zero-based row and column indices.
+
+ Additional kwargs are matplotlib.artist properties
+
+ """
+
+ self._extent = extent
+
+ _AxesImageBase.__init__(self, ax,
+ cmap = cmap,
+ norm = norm,
+ interpolation=interpolation,
+ origin=origin,
+ filternorm=filternorm,
+ filterrad=filterrad,
+ resample = resample,
+ **kwargs
+ )
+
+
+ def make_image(self, magnification=1.0):
+ if self._A is None:
+ raise RuntimeError('You must first set the image array or the image attribute')
+
+ xmin, xmax, ymin, ymax = self.get_extent()
+ dxintv = xmax-xmin
+ dyintv = ymax-ymin
+
+ # the viewport scale factor
+ sx = dxintv/self.axes.viewLim.width
+ sy = dyintv/self.axes.viewLim.height
+ numrows, numcols = self._A.shape[:2]
+ if sx > 2:
+ x0 = (self.axes.viewLim.x0-xmin)/dxintv * numcols
+ ix0 = max(0, int(x0 - self._filterrad))
+ x1 = (self.axes.viewLim.x1-xmin)/dxintv * numcols
+ ix1 = min(numcols, int(x1 + self._filterrad))
+ xslice = slice(ix0, ix1)
+ xmin_old = xmin
+ xmin = xmin_old + ix0*dxintv/numcols
+ xmax = xmin_old + ix1*dxintv/numcols
+ dxintv = xmax - xmin
+ sx = dxintv/self.axes.viewLim.width
+ else:
+ xslice = slice(0, numcols)
+
+ if sy > 2:
+ y0 = (self.axes.viewLim.y0-ymin)/dyintv * numrows
+ iy0 = max(0, int(y0 - self._filterrad))
+ y1 = (self.axes.viewLim.y1-ymin)/dyintv * numrows
+ iy1 = min(numrows, int(y1 + self._filterrad))
+ if self.origin == 'upper':
+ yslice = slice(numrows-iy1, numrows-iy0)
+ else:
+ yslice = slice(iy0, iy1)
+ ymin_old = ymin
+ ymin = ymin_old + iy0*dyintv/numrows
+ ymax = ymin_old + iy1*dyintv/numrows
+ dyintv = ymax - ymin
+ sy = dyintv/self.axes.viewLim.height
+ else:
+ yslice = slice(0, numrows)
+
+ if xslice != self._oldxslice or yslice != self._oldyslice:
+ self._imcache = None
+ self._oldxslice = xslice
+ self._oldyslice = yslice
+
+ if self._imcache is None:
+ if self._A.dtype == np.uint8 and len(self._A.shape) == 3:
+ im = _image.frombyte(self._A[yslice,xslice,:], 0)
+ im.is_grayscale = False
+ else:
+ if self._rgbacache is None:
+ x = self.to_rgba(self._A, self._alpha)
+ self._rgbacache = x
+ else:
+ x = self._rgbacache
+ im = _image.fromarray(x[yslice,xslice], 0)
+ if len(self._A.shape) == 2:
+ im.is_grayscale = self.cmap.is_gray()
+ else:
+ im.is_grayscale = False
+ self._imcache = im
+
+ if self.origin=='upper':
+ im.flipud_in()
+ else:
+ im = self._imcache
+
+ fc = self.axes.patch.get_facecolor()
+ bg = mcolors.colorConverter.to_rgba(fc, 0)
+ im.set_bg( *bg)
+
+ # image input dimensions
+ im.reset_matrix()
+ numrows, numcols = im.get_size()
+
+ im.set_interpolation(self._interpd[self._interpolation])
+
+ im.set_resample(self._resample)
+
+ # the viewport translation
+ tx = (xmin-self.axes.viewLim.x0)/dxintv * numcols
+ ty = (ymin-self.axes.viewLim.y0)/dyintv * numrows
+
+ l, b, r, t = self.axes.bbox.extents
+ widthDisplay = (round(r) + 0.5) - (round(l) - 0.5)
+ heightDisplay = (round(t) + 0.5) - (round(b) - 0.5)
+ widthDisplay *= magnification
+ heightDisplay *= magnification
+ im.apply_translation(tx, ty)
+
+ # resize viewport to display
+ rx = widthDisplay / numcols
+ ry = heightDisplay / numrows
+ im.apply_scaling(rx*sx, ry*sy)
+ im.resize(int(widthDisplay+0.5), int(heightDisplay+0.5),
+ norm=self._filternorm, radius=self._filterrad)
+ return im
+
+
+ def set_extent(self, extent):
+ """
+ extent is data axes (left, right, bottom, top) for making image plots
+ """
+ self._extent = extent
+
+ xmin, xmax, ymin, ymax = extent
+ corners = (xmin, ymin), (xmax, ymax)
+ self.axes.update_datalim(corners)
+ if self.axes._autoscaleXon:
+ self.axes.set_xlim((xmin, xmax))
+ if self.axes._autoscaleYon:
+ self.axes.set_ylim((ymin, ymax))
+
+ def get_extent(self):
+ 'get the image extent: left, right, bottom, top'
+ if self._extent is not None:
+ return self._extent
+ else:
+ sz = self.get_size()
+ #print 'sz', sz
+ numrows, numcols = sz
+ if self.origin == 'upper':
+ return (-0.5, numcols-0.5, numrows-0.5, -0.5)
+ else:
+ return (-0.5, numcols-0.5, -0.5, numrows-0.5)
+
+
+
 class NonUniformImage(AxesImage):
 def __init__(self, ax, **kwargs):
 """
@@ -747,7 +795,7 @@
 _png.write_png(buffer, cols, rows, fname)
 
 
-class BboxImage(AxesImage):
+class BboxImage(_AxesImageBase):
 """
 The Image class whose size is determined by the given bbox.
 """
@@ -770,16 +818,16 @@
 kwargs are an optional list of Artist keyword args
 """
 
- AxesImage.__init__(self, ax=None,
- cmap = cmap,
- norm = norm,
- interpolation=interpolation,
- origin=origin,
- filternorm=filternorm,
- filterrad=filterrad,
- resample = resample,
- **kwargs
- )
+ _AxesImageBase.__init__(self, ax=None,
+ cmap = cmap,
+ norm = norm,
+ interpolation=interpolation,
+ origin=origin,
+ filternorm=filternorm,
+ filterrad=filterrad,
+ resample = resample,
+ **kwargs
+ )
 
 self.bbox = bbox
 
@@ -842,11 +890,6 @@
 else:
 im = self._imcache
 
- if 0:
- fc = self.axes.patch.get_facecolor()
- bg = mcolors.colorConverter.to_rgba(fc, 0)
- im.set_bg( *bg)
-
 # image input dimensions
 im.reset_matrix()
 
@@ -859,7 +902,6 @@
 heightDisplay = (round(t) + 0.5) - (round(b) - 0.5)
 widthDisplay *= magnification
 heightDisplay *= magnification
- #im.apply_translation(tx, ty)
 
 numrows, numcols = self._A.shape[:2]
 
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <as...@us...> - 2009年11月12日 23:06:32
Revision: 7960
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7960&view=rev
Author: astraw
Date: 2009年11月12日 23:05:45 +0000 (2009年11月12日)
Log Message:
-----------
image.py: change default image zorder 1 -> 0
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/image.py
Modified: trunk/matplotlib/lib/matplotlib/image.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/image.py	2009年11月12日 22:49:37 UTC (rev 7959)
+++ trunk/matplotlib/lib/matplotlib/image.py	2009年11月12日 23:05:45 UTC (rev 7960)
@@ -27,7 +27,7 @@
 from matplotlib.transforms import BboxBase
 
 class _AxesImageBase(martist.Artist, cm.ScalarMappable):
- zorder = 1
+ zorder = 0
 # map interpolation strings to module constants
 _interpd = {
 'nearest' : _image.NEAREST,
@@ -687,7 +687,7 @@
 self.update_dict['array'] = True
 
 class FigureImage(martist.Artist, cm.ScalarMappable):
- zorder = 1
+ zorder = 0
 def __init__(self, fig,
 cmap = None,
 norm = None,
@@ -805,7 +805,6 @@
 """
 The Image class whose size is determined by the given bbox.
 """
- zorder = 1
 def __init__(self, bbox,
 cmap = None,
 norm = None,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <lee...@us...> - 2010年02月08日 16:54:37
Revision: 8119
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8119&view=rev
Author: leejjoon
Date: 2010年02月08日 16:54:31 +0000 (2010年2月08日)
Log Message:
-----------
issue a warning when _image_skew_coordinate is set for backends that do not support an affine transform of images
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/image.py
Modified: trunk/matplotlib/lib/matplotlib/image.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/image.py	2010年02月08日 16:54:26 UTC (rev 8118)
+++ trunk/matplotlib/lib/matplotlib/image.py	2010年02月08日 16:54:31 UTC (rev 8119)
@@ -305,6 +305,9 @@
 if self._check_unsampled_image(renderer):
 self._draw_unsampled_image(renderer, gc)
 else:
+ if self._image_skew_coordinate is not None:
+ warnings.warn("Image will not be shown correctly with this backend.")
+
 im = self.make_image(renderer.get_image_magnification())
 if im is None:
 return
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <lee...@us...> - 2010年03月04日 00:05:23
Revision: 8178
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8178&view=rev
Author: leejjoon
Date: 2010年03月04日 00:05:17 +0000 (2010年3月04日)
Log Message:
-----------
make NonUniformImage not to use unsampled_image
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/image.py
Modified: trunk/matplotlib/lib/matplotlib/image.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/image.py	2010年03月03日 21:33:35 UTC (rev 8177)
+++ trunk/matplotlib/lib/matplotlib/image.py	2010年03月04日 00:05:17 UTC (rev 8178)
@@ -592,6 +592,12 @@
 **kwargs)
 AxesImage.set_interpolation(self, interp)
 
+ def _check_unsampled_image(self, renderer):
+ """
+ return False. Do not use unsampled image.
+ """
+ return False
+
 def make_image(self, magnification=1.0):
 if self._A is None:
 raise RuntimeError('You must first set the image array')
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <lee...@us...> - 2010年06月06日 04:18:59
Revision: 8386
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8386&view=rev
Author: leejjoon
Date: 2010年06月06日 04:18:53 +0000 (2010年6月06日)
Log Message:
-----------
Image in non-linear coordinates correctly have their coners at its extents
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/image.py
Modified: trunk/matplotlib/lib/matplotlib/image.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/image.py	2010年06月05日 18:32:11 UTC (rev 8385)
+++ trunk/matplotlib/lib/matplotlib/image.py	2010年06月06日 04:18:53 UTC (rev 8386)
@@ -135,7 +135,7 @@
 raise RuntimeError('The make_image method must be overridden.')
 
 
- def _get_unsampled_image(self, A, image_extents, viewlim):
+ def _get_unsampled_image(self, A, image_extents, viewlim, noslice=False):
 """
 convert numpy array A with given extents ([x1, x2, y1, y2] in
 data coordinate) into the Image, given the vielim (should be a
@@ -150,7 +150,7 @@
 sx = dxintv/viewlim.width
 sy = dyintv/viewlim.height
 numrows, numcols = A.shape[:2]
- if sx > 2:
+ if noslice is False and sx > 2:
 x0 = (viewlim.x0-xmin)/dxintv * numcols
 ix0 = max(0, int(x0 - self._filterrad))
 x1 = (viewlim.x1-xmin)/dxintv * numcols
@@ -164,7 +164,7 @@
 else:
 xslice = slice(0, numcols)
 
- if sy > 2:
+ if noslice is False and sy > 2:
 y0 = (viewlim.y0-ymin)/dyintv * numrows
 iy0 = max(0, int(y0 - self._filterrad))
 y1 = (viewlim.y1-ymin)/dyintv * numrows
@@ -246,8 +246,11 @@
 draw unsampled image. The renderer should support a draw_image method
 with scale parameter.
 """
+
+
 im, xmin, ymin, dxintv, dyintv, sx, sy = \
- self._get_unsampled_image(self._A, self.get_extent(), self.axes.viewLim)
+ self._get_unsampled_image(self._A, self.get_extent(),
+ self.axes.viewLim, noslice=True)
 
 if im is None: return # I'm not if this check is required. -JJL
 
@@ -264,18 +267,23 @@
 im._url = self.get_url()
 
 trans = self.get_transform() #axes.transData
- xy = trans.transform_non_affine([(xmin, ymin),
- (xmin+dxintv, ymin+dyintv)])
+ xy = trans.transform_non_affine(np.array([(xmin, ymin),
+ (xmin+dxintv, ymin+dyintv)]))
 xx1, yy1 = xy[0]
 xx2, yy2 = xy[1]
 
 if self._image_skew_coordinate:
 # skew the image when required.
+ x_llc, x_trc, y_llc, y_trc = self.get_extent()
 x_lrc, y_lrc = self._image_skew_coordinate
- xy = trans.transform_non_affine([(x_lrc, y_lrc)])
- xx3, yy3 = xy[0]
+ xy = trans.transform_non_affine(np.array([(x_llc, y_llc),
+ (x_trc, y_trc),
+ (x_lrc, y_lrc)]))
+ _xx1, _yy1 = xy[0]
+ _xx2, _yy2 = xy[1]
+ _xx3, _yy3 = xy[2]
 
- tr_rotate_skew = self._get_rotate_and_skew_transform(xx1, yy1, xx2, yy2, xx3, yy3)
+ tr_rotate_skew = self._get_rotate_and_skew_transform(_xx1, _yy1, _xx2, _yy2, _xx3, _yy3)
 tr = tr_rotate_skew+trans.get_affine()
 else:
 tr = trans.get_affine()
@@ -509,8 +517,21 @@
 if self._A is None:
 raise RuntimeError('You must first set the image array or the image attribute')
 
+ # image is created in the canvas coordinate.
+ x1, x2, y1, y2 = self.get_extent()
+ trans = self.get_transform()
+ xy = trans.transform(np.array([(x1, y1),
+ (x2, y2),
+ ]))
+ _x1, _y1 = xy[0]
+ _x2, _y2 = xy[1]
+
+ transformed_viewLim = mtransforms.TransformedBbox(self.axes.viewLim,
+ trans)
+
 im, xmin, ymin, dxintv, dyintv, sx, sy = \
- self._get_unsampled_image(self._A, self.get_extent(), self.axes.viewLim)
+ self._get_unsampled_image(self._A, [_x1, _x2, _y1, _y2],
+ transformed_viewLim)
 
 fc = self.axes.patch.get_facecolor()
 bg = mcolors.colorConverter.to_rgba(fc, 0)
@@ -526,8 +547,8 @@
 im.set_resample(self._resample)
 
 # the viewport translation
- tx = (xmin-self.axes.viewLim.x0)/dxintv * numcols
- ty = (ymin-self.axes.viewLim.y0)/dyintv * numrows
+ tx = (xmin-transformed_viewLim.x0)/dxintv * numcols
+ ty = (ymin-transformed_viewLim.y0)/dyintv * numrows
 
 l, b, r, t = self.axes.bbox.extents
 widthDisplay = (round(r*magnification) + 0.5) - (round(l*magnification) - 0.5)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <lee...@us...> - 2010年06月27日 02:07:23
Revision: 8472
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8472&view=rev
Author: leejjoon
Date: 2010年06月27日 02:07:17 +0000 (2010年6月27日)
Log Message:
-----------
_get_unsampled_image now returns a sliced image if possible
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/image.py
Modified: trunk/matplotlib/lib/matplotlib/image.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/image.py	2010年06月26日 19:29:48 UTC (rev 8471)
+++ trunk/matplotlib/lib/matplotlib/image.py	2010年06月27日 02:07:17 UTC (rev 8472)
@@ -24,7 +24,7 @@
 # the image namespace:
 from matplotlib._image import *
 
-from matplotlib.transforms import BboxBase
+from matplotlib.transforms import BboxBase, Bbox
 import matplotlib.transforms as mtransforms
 
 class _AxesImageBase(martist.Artist, cm.ScalarMappable):
@@ -135,7 +135,7 @@
 raise RuntimeError('The make_image method must be overridden.')
 
 
- def _get_unsampled_image(self, A, image_extents, viewlim, noslice=False):
+ def _get_unsampled_image(self, A, image_extents, viewlim):
 """
 convert numpy array A with given extents ([x1, x2, y1, y2] in
 data coordinate) into the Image, given the vielim (should be a
@@ -150,7 +150,7 @@
 sx = dxintv/viewlim.width
 sy = dyintv/viewlim.height
 numrows, numcols = A.shape[:2]
- if noslice is False and sx > 2:
+ if sx > 2:
 x0 = (viewlim.x0-xmin)/dxintv * numcols
 ix0 = max(0, int(x0 - self._filterrad))
 x1 = (viewlim.x1-xmin)/dxintv * numcols
@@ -164,7 +164,7 @@
 else:
 xslice = slice(0, numcols)
 
- if noslice is False and sy > 2:
+ if sy > 2:
 y0 = (viewlim.y0-ymin)/dyintv * numrows
 iy0 = max(0, int(y0 - self._filterrad))
 y1 = (viewlim.y1-ymin)/dyintv * numrows
@@ -248,9 +248,57 @@
 """
 
 
+ trans = self.get_transform() #axes.transData
+
+ # convert the coordinates to the intermediate coordinate (ic).
+ # The transformation from the ic to the canvas is a pure
+ # affine transfor.
+
+ # A straight-forward way is to use the non-affine part of the
+ # original transform for conversion to the ic.
+
+ # firs, convert the image extent to the ic
+ x_llc, x_trc, y_llc, y_trc = self.get_extent()
+
+ xy = trans.transform_non_affine(np.array([(x_llc, y_llc),
+ (x_trc, y_trc)]))
+
+ _xx1, _yy1 = xy[0]
+ _xx2, _yy2 = xy[1]
+
+ extent_in_ic = _xx1, _xx2, _yy1, _yy2
+
+ # define trans_ic_to_canvas : unless _image_skew_coordinate is
+ # set, it is simply a affine part of the original transform.
+ if self._image_skew_coordinate:
+ # skew the image when required.
+ x_lrc, y_lrc = self._image_skew_coordinate
+ xy2 = trans.transform_non_affine(np.array([(x_lrc, y_lrc)]))
+ _xx3, _yy3 = xy2[0]
+
+ tr_rotate_skew = self._get_rotate_and_skew_transform(_xx1, _yy1,
+ _xx2, _yy2,
+ _xx3, _yy3)
+ trans_ic_to_canvas = tr_rotate_skew+trans.get_affine()
+ else:
+ trans_ic_to_canvas = trans.get_affine()
+
+ # Now, viewLim in the ic. It can be roated and can be
+ # skewed. Make it big enough.
+ x1, y1, x2, y2 = self.axes.bbox.extents
+ trans_canvas_to_ic = trans_ic_to_canvas.inverted()
+ xy_ = trans_canvas_to_ic.transform(np.array([(x1, y1),
+ (x2, y1),
+ (x2, y2),
+ (x1, y2)]))
+ x1_, x2_ = min(xy_[:,0]), max(xy_[:,0])
+ y1_, y2_ = min(xy_[:,1]), max(xy_[:,1])
+ viewLim_in_ic = Bbox.from_extents(x1_, y1_, x2_, y2_)
+
+
+ # get the image, sliced if necessary. This is done in the ic.
 im, xmin, ymin, dxintv, dyintv, sx, sy = \
- self._get_unsampled_image(self._A, self.get_extent(),
- self.axes.viewLim, noslice=True)
+ self._get_unsampled_image(self._A, extent_in_ic, viewLim_in_ic)
 
 if im is None: return # I'm not if this check is required. -JJL
 
@@ -262,35 +310,16 @@
 im.reset_matrix()
 numrows, numcols = im.get_size()
 
- im.resize(numcols, numrows) # just to create im.bufOut that is required by backends. There may be better solution -JJL
+ im.resize(numcols, numrows) # just to create im.bufOut that
+ # is required by backends. There
+ # may be better solution -JJL
 
 im._url = self.get_url()
 
- trans = self.get_transform() #axes.transData
- xy = trans.transform_non_affine(np.array([(xmin, ymin),
- (xmin+dxintv, ymin+dyintv)]))
- xx1, yy1 = xy[0]
- xx2, yy2 = xy[1]
+ renderer.draw_image(gc, xmin, ymin, im, dxintv, dyintv,
+ trans_ic_to_canvas)
 
- if self._image_skew_coordinate:
- # skew the image when required.
- x_llc, x_trc, y_llc, y_trc = self.get_extent()
- x_lrc, y_lrc = self._image_skew_coordinate
- xy = trans.transform_non_affine(np.array([(x_llc, y_llc),
- (x_trc, y_trc),
- (x_lrc, y_lrc)]))
- _xx1, _yy1 = xy[0]
- _xx2, _yy2 = xy[1]
- _xx3, _yy3 = xy[2]
 
- tr_rotate_skew = self._get_rotate_and_skew_transform(_xx1, _yy1, _xx2, _yy2, _xx3, _yy3)
- tr = tr_rotate_skew+trans.get_affine()
- else:
- tr = trans.get_affine()
-
- renderer.draw_image(gc, xx1, yy1, im, xx2-xx1, yy2-yy1, tr)
-
-
 def _check_unsampled_image(self, renderer):
 """
 return True if the image is better to be drawn unsampled.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /