From: <as...@us...> - 2009-12-21 02:24:28
|
Revision: 8047 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8047&view=rev Author: astraw Date: 2009-12-21 02:24:14 +0000 (Mon, 21 Dec 2009) Log Message: ----------- spines: attempt to fix initial placement bug Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/axes.py trunk/matplotlib/lib/matplotlib/spines.py Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2009-12-21 00:47:49 UTC (rev 8046) +++ trunk/matplotlib/lib/matplotlib/axes.py 2009-12-21 02:24:14 UTC (rev 8047) @@ -2065,9 +2065,6 @@ other.figure.canvas is not None): other.figure.canvas.draw_idle() - for loc in ('bottom','top'): - self.spines[loc].set_bounds(xmin,xmax) - return xmin, xmax def get_xscale(self): @@ -2242,9 +2239,6 @@ other.figure.canvas is not None): other.figure.canvas.draw_idle() - for loc in ('left','right'): - self.spines[loc].set_bounds(ymin,ymax) - return ymin, ymax def get_yscale(self): Modified: trunk/matplotlib/lib/matplotlib/spines.py =================================================================== --- trunk/matplotlib/lib/matplotlib/spines.py 2009-12-21 00:47:49 UTC (rev 8046) +++ trunk/matplotlib/lib/matplotlib/spines.py 2009-12-21 02:24:14 UTC (rev 8047) @@ -11,6 +11,7 @@ import matplotlib.patches as mpatches import matplotlib.path as mpath import matplotlib.cbook as cbook +import numpy as np import warnings class Spine(mpatches.Patch): @@ -57,6 +58,8 @@ self.set_zorder(2.5) self.set_transform(self.axes.transData) # default transform + self._bounds = None # default bounds + # Defer initial position determination. (Not much support for # non-rectangular axes is currently implemented, and this lets # them pass through the spines machinery without errors.) @@ -138,6 +141,39 @@ if self.axis is not None: self.axis.cla() + def _adjust_location(self): + """automatically set spine bounds to the view interval""" + + if self.spine_type == 'circle': + return + + if self._bounds is None: + if self.spine_type in ('left','right'): + low,high = self.axes.viewLim.intervaly + elif self.spine_type in ('top','bottom'): + low,high = self.axes.viewLim.intervalx + else: + raise ValueError('unknown spine spine_type: %s'%self.spine_type) + else: + low,high = self._bounds + + v1 = self._path.vertices[:] # copy + assert v1.shape == (2,2), 'unexpected vertices shape' + if self.spine_type in ['left','right']: + v1[0,1] = low + v1[1,1] = high + elif self.spine_type in ['bottom','top']: + v1[0,0] = low + v1[1,0] = high + else: + raise ValueError('unable to set bounds for spine "%s"'%spine_type) + self._path.vertices = v1 # replace + + @allow_rasterization + def draw(self, renderer): + self._adjust_location() + return super( Spine, self).draw(renderer) + def _calc_offset_transform(self): """calculate the offset transform performed by the spine""" self._ensure_position_is_set() @@ -280,17 +316,10 @@ raise ValueError("unknown spine_transform type: %s"%what) def set_bounds( self, low, high ): - v1 = self._path.vertices[:] # copy - assert v1.shape == (2,2), 'unexpected vertices shape' - if self.spine_type in ['left','right']: - v1[0,1] = low - v1[1,1] = high - elif self.spine_type in ['bottom','top']: - v1[0,0] = low - v1[1,0] = high - else: - raise ValueError('unable to set bounds for spine "%s"'%spine_type) - self._path.vertices = v1 # replace + if self.spine_type == 'circle': + raise ValueError( + 'set_bounds() method incompatible with circular spines') + self._bounds = (low, high) @classmethod def linear_spine(cls, axes, spine_type, **kwargs): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |