Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 00cfd28

Browse files
committed
spines: default transform is in data units, add set_bounds() call
svn path=/trunk/matplotlib/; revision=8044
1 parent 4ab2610 commit 00cfd28

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2009-12-20 spines: put spines in data coordinates, add set_bounds()
2+
call. -ADS
3+
14
2009-12-18 Don't limit notch size in boxplot to q1-q3 range, as this
25
is effectively making the data look better than it is. - ADS
36

lib/matplotlib/axes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,6 +2065,9 @@ def set_xlim(self, xmin=None, xmax=None, emit=True, **kwargs):
20652065
other.figure.canvas is not None):
20662066
other.figure.canvas.draw_idle()
20672067

2068+
for loc in ('bottom','top'):
2069+
self.spines[loc].set_bounds(xmin,xmax)
2070+
20682071
return xmin, xmax
20692072

20702073
def get_xscale(self):
@@ -2238,6 +2241,10 @@ def set_ylim(self, ymin=None, ymax=None, emit=True, **kwargs):
22382241
if (other.figure != self.figure and
22392242
other.figure.canvas is not None):
22402243
other.figure.canvas.draw_idle()
2244+
2245+
for loc in ('left','right'):
2246+
self.spines[loc].set_bounds(ymin,ymax)
2247+
22412248
return ymin, ymax
22422249

22432250
def get_yscale(self):

lib/matplotlib/spines.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __init__(self,axes,spine_type,path,**kwargs):
5555
self.axis = None
5656

5757
self.set_zorder(2.5)
58-
self.set_transform(self.axes.transAxes) # default transform
58+
self.set_transform(self.axes.transData) # default transform
5959

6060
# Defer initial position determination. (Not much support for
6161
# non-rectangular axes is currently implemented, and this lets
@@ -82,6 +82,7 @@ def set_patch_circle(self,center,radius):
8282
self._width = radius*2
8383
self._height = radius*2
8484
self._angle = 0
85+
self.set_transform(self.axes.transAxes) # circle drawn on axes transform
8586

8687
def set_patch_line(self):
8788
"""set the spine to be linear"""
@@ -229,9 +230,9 @@ def set_position(self,position):
229230
t = self.get_spine_transform()
230231
if self.spine_type in ['left','right']:
231232
t2 = mtransforms.blended_transform_factory(t,
232-
self.axes.transAxes)
233+
self.axes.transData)
233234
elif self.spine_type in ['bottom','top']:
234-
t2 = mtransforms.blended_transform_factory(self.axes.transAxes,
235+
t2 = mtransforms.blended_transform_factory(self.axes.transData,
235236
t)
236237
self.set_transform(t2)
237238

@@ -278,6 +279,19 @@ def get_spine_transform(self):
278279
else:
279280
raise ValueError("unknown spine_transform type: %s"%what)
280281

282+
def set_bounds( self, low, high ):
283+
v1 = self._path.vertices[:] # copy
284+
assert v1.shape == (2,2), 'unexpected vertices shape'
285+
if self.spine_type in ['left','right']:
286+
v1[0,1] = low
287+
v1[1,1] = high
288+
elif self.spine_type in ['bottom','top']:
289+
v1[0,0] = low
290+
v1[1,0] = high
291+
else:
292+
raise ValueError('unable to set bounds for spine "%s"'%spine_type)
293+
self._path.vertices = v1 # replace
294+
281295
@classmethod
282296
def linear_spine(cls, axes, spine_type, **kwargs):
283297
"""

0 commit comments

Comments
 (0)