From: <md...@us...> - 2007-09-19 13:28:21
|
Revision: 3857 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3857&view=rev Author: mdboom Date: 2007-09-19 06:28:11 -0700 (Wed, 19 Sep 2007) Log Message: ----------- Got legend working with new transforms Modified Paths: -------------- branches/transforms/lib/matplotlib/axes.py branches/transforms/lib/matplotlib/legend.py branches/transforms/lib/matplotlib/lines.py branches/transforms/lib/matplotlib/patches.py branches/transforms/lib/matplotlib/transforms.py Modified: branches/transforms/lib/matplotlib/axes.py =================================================================== --- branches/transforms/lib/matplotlib/axes.py 2007-09-18 19:29:21 UTC (rev 3856) +++ branches/transforms/lib/matplotlib/axes.py 2007-09-19 13:28:11 UTC (rev 3857) @@ -632,6 +632,7 @@ self.transAxes = mtransforms.BboxTransform( mtransforms.Bbox.unit(), self.bbox) + # self.set_transform(self.transAxes) self.transData = mtransforms.BboxTransform( self.viewLim, self.bbox) @@ -724,6 +725,7 @@ self.axesPatch.set_figure(self.figure) self.axesPatch.set_transform(self.transAxes) self.axesPatch.set_linewidth(rcParams['axes.linewidth']) + # MGDTODO: What is axesFrame for? We already have axesPatch self.axesFrame = mlines.Line2D((0,1,1,0,0), (0,0,1,1,0), linewidth=rcParams['axes.linewidth'], color=rcParams['axes.edgecolor'], @@ -5201,7 +5203,7 @@ Subplot(211) # 2 rows, 1 column, first (upper) plot """ def __str__(self): - return "Subplot(%g,%g)"%(self.bottom.get(),self.left.get()) + return "Subplot(%f,%f,%f,%f)" % (self.bbox.bounds) def __init__(self, fig, *args, **kwargs): """ Modified: branches/transforms/lib/matplotlib/legend.py =================================================================== --- branches/transforms/lib/matplotlib/legend.py 2007-09-18 19:29:21 UTC (rev 3856) +++ branches/transforms/lib/matplotlib/legend.py 2007-09-19 13:28:11 UTC (rev 3857) @@ -164,7 +164,7 @@ else: raise TypeError("Legend needs either Axes or Figure as parent") self.parent = parent - self.set_transform( BboxTransform( Bbox.unit(), parent.bbox) ) + self.set_transform( BboxTransform(Bbox.unit(), parent.bbox) ) if loc is None: loc = rcParams["legend.loc"] @@ -223,7 +223,7 @@ a.set_transform(self.get_transform()) def _approx_text_height(self): - return self.fontsize/72.0*self.figure.dpi/self.parent.bbox.height() + return self.fontsize/72.0*self.figure.dpi/self.parent.bbox.height def draw(self, renderer): @@ -531,7 +531,7 @@ def get_tbounds(text): #get text bounds in axes coords bbox = text.get_window_extent(renderer) bboxa = bbox.inverse_transformed(self.get_transform()) - return bboxa.get_bounds() + return bboxa.bounds hpos = [] for t, tabove in zip(self.texts[1:], self.texts[:-1]): @@ -560,10 +560,10 @@ # Set the data for the legend patch bbox = copy.copy(self._get_handle_text_bbox(renderer)) - bbox = bbox.scaled(1 + self.pad, 1 + self.pad) - l,b,w,h = bbox.get_bounds() - self.legendPatch.set_bounds(l,b,w,h) - + bbox = bbox.expanded(1 + self.pad, 1 + self.pad) + l, b, w, h = bbox.bounds + self.legendPatch.set_bounds(l, b, w, h) + ox, oy = 0, 0 # center if iterable(self._loc) and len(self._loc)==2: Modified: branches/transforms/lib/matplotlib/lines.py =================================================================== --- branches/transforms/lib/matplotlib/lines.py 2007-09-18 19:29:21 UTC (rev 3856) +++ branches/transforms/lib/matplotlib/lines.py 2007-09-19 13:28:11 UTC (rev 3857) @@ -117,7 +117,7 @@ '--' : '_draw_dashed', '-.' : '_draw_dash_dot', ':' : '_draw_dotted', - 'steps': '_draw_steps', + 'steps': '_draw_solid', 'None' : '_draw_nothing', ' ' : '_draw_nothing', '' : '_draw_nothing', @@ -352,10 +352,10 @@ self._picker = p def get_window_extent(self, renderer): - xys = self.get_transform()(self._xys) + xy = self.get_transform()(self._xy) - x = xys[:, 0] - y = xys[:, 1] + x = xy[:, 0] + y = xy[:, 1] left = x.min() bottom = y.min() width = x.max() - left @@ -426,9 +426,19 @@ npy.asarray(y, npy.float_))).transpose() self._x = self._xy[:, 0] self._y = self._xy[:, 1] - self._path = Path(self._xy, closed=False) - self._logcache = None + + if self._linestyle == 'steps': + siz=len(xt) + if siz<2: return + xt, yt = self._x, self._y + xt2=npy.ones((2*siz,), xt.dtype) + xt2[0:-1:2], xt2[1:-1:2], xt2[-1] = xt, xt[1:], xt[-1] + yt2=npy.ones((2*siz,), yt.dtype) + yt2[0:-1:2], yt2[1::2] = yt, yt + self._path = Path(npy.vstack((xt2, yt2)).transpose(), closed=False) + else: + self._path = Path(self._xy, closed=False) def _is_sorted(self, x): @@ -700,24 +710,6 @@ pass - def _draw_steps(self, renderer, gc, xt, yt): - # MGDTODO: This is a quirky one. The step-plotting part - # should probably be moved to where the path is generated - # in recache, and then just drawn with _draw_solid - siz=len(xt) - if siz<2: return - xt2=npy.ones((2*siz,), xt.dtype) - xt2[0:-1:2], xt2[1:-1:2], xt2[-1]=xt, xt[1:], xt[-1] - yt2=npy.ones((2*siz,), yt.dtype) - yt2[0:-1:2], yt2[1::2]=yt, yt - gc.set_linestyle('solid') - - if self._newstyle: - renderer.draw_lines(gc, xt2, yt2, self.get_transform()) - else: - renderer.draw_lines(gc, xt2, yt2) - - def _draw_solid(self, renderer, gc, path): gc.set_linestyle('solid') renderer.draw_path(gc, path, self.get_transform()) Modified: branches/transforms/lib/matplotlib/patches.py =================================================================== --- branches/transforms/lib/matplotlib/patches.py 2007-09-18 19:29:21 UTC (rev 3856) +++ branches/transforms/lib/matplotlib/patches.py 2007-09-19 13:28:11 UTC (rev 3857) @@ -212,8 +212,8 @@ gc.set_hatch(self._hatch ) path = self.get_path() - transform = self.get_transform() - + transform = self.get_patch_transform() + self.get_transform() + renderer.draw_path(gc, path, transform, rgbFace) #renderer.close_group('patch') @@ -284,7 +284,7 @@ self.patch = patch self.props = props self.ox, self.oy = ox, oy - self._shadow_transform = transforms.Affine2D.translate(self.ox, self.oy) + self._shadow_transform = transforms.Affine2D().translate(self.ox, self.oy) self._update() __init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd @@ -305,8 +305,8 @@ def get_path(self): return self.patch.get_path() - def get_transform(self): - return self._transform + self._shadow_transform + def get_patch_transform(self): + return self._shadow_transform class Rectangle(Patch): """ @@ -315,8 +315,6 @@ """ - _path = Path.unit_rectangle() - def __str__(self): return str(self.__class__).split('.')[-1] \ + "(%g,%g;%gx%g)"%(self.xy[0],self.xy[1],self.width,self.height) @@ -346,16 +344,14 @@ """ Return the vertices of the rectangle """ - # This is a "class-static" variable, so all rectangles in the plot - # will be shared (and merely have different transforms) - return self._path + return Path.unit_rectangle() # MGDTODO: Convert units # left, right = self.convert_xunits((x, x + self.width)) # bottom, top = self.convert_yunits((y, y + self.height)) - def get_transform(self): - return self._rect_transform + self._transform + def get_patch_transform(self): + return self._rect_transform def get_x(self): "Return the left coord of the rectangle" @@ -379,7 +375,8 @@ ACCEPTS: float """ - self._bbox.xmin = x + w = self._bbox.width + self._bbox.intervalx = (x, x + w) def set_y(self, y): """ @@ -387,7 +384,8 @@ ACCEPTS: float """ - self._bbox.ymin = y + h = self._bbox.height + self._bbox.intervaly = (y, y + h) def set_width(self, w): """ @@ -395,7 +393,7 @@ ACCEPTS: float """ - self._bbox.width = w + self._bbox.xmax = self._bbox.xmin + w def set_height(self, h): """ @@ -403,7 +401,7 @@ ACCEPTS: float """ - self._bbox.height = h + self._bbox.ymax = self._bbox.ymin + h def set_bounds(self, *args): """ Modified: branches/transforms/lib/matplotlib/transforms.py =================================================================== --- branches/transforms/lib/matplotlib/transforms.py 2007-09-18 19:29:21 UTC (rev 3856) +++ branches/transforms/lib/matplotlib/transforms.py 2007-09-19 13:28:11 UTC (rev 3857) @@ -8,6 +8,8 @@ from numpy.linalg import inv from sets import Set +DEBUG = True + # MGDTODO: This creates a ton of cyclical references. We may want to # consider using weak references @@ -53,6 +55,13 @@ def __array__(self): return self.get_points() + + if DEBUG: + def invalidate(self): + points = self.get_points() + assert points[0, 0] <= points[1, 0] + assert points[0, 1] <= points[1, 1] + TransformNode.invalidate(self) # MGDTODO: Probably a more efficient ways to do this... def _get_xmin(self): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |