@@ -1581,8 +1581,8 @@ def set_ticks(self, ticks, minor=False):
1581
1581
1582
1582
def _update_label_position (self , bboxes , bboxes2 ):
1583
1583
"""
1584
- Update the label position based on the sequence of bounding
1585
- boxes of all the ticklabels
1584
+ Update the label position based on the the bounding box enclosing
1585
+ all the ticklabels and axis spine
1586
1586
"""
1587
1587
raise NotImplementedError ('Derived must override' )
1588
1588
@@ -1737,28 +1737,38 @@ def set_label_position(self, position):
1737
1737
1738
1738
def _update_label_position (self , bboxes , bboxes2 ):
1739
1739
"""
1740
- Update the label position based on the sequence of bounding
1741
- boxes of all the ticklabels
1740
+ Update the label position based on the the bounding box enclosing
1741
+ all the ticklabels and axis spine
1742
1742
"""
1743
1743
if not self ._autolabelpos :
1744
1744
return
1745
1745
x , y = self .label .get_position ()
1746
1746
if self .label_position == 'bottom' :
1747
- if not len (bboxes ):
1748
- bottom = self .axes .bbox .ymin
1749
- else :
1750
- bbox = mtransforms .Bbox .union (bboxes )
1751
- bottom = bbox .y0
1747
+ try :
1748
+ spine = self .axes .spines ['bottom' ]
1749
+ spinebbox = spine .get_transform ().transform_path (
1750
+ spine .get_path ()).get_extents ()
1751
+ except KeyError :
1752
+ # use axes if spine doesn't exist
1753
+ spinebbox = self .axes .bbox
1754
+ bbox = mtransforms .Bbox .union (bboxes + [spinebbox ])
1755
+ bottom = bbox .y0
1756
+
1752
1757
self .label .set_position (
1753
1758
(x , bottom - self .labelpad * self .figure .dpi / 72.0 )
1754
1759
)
1755
1760
1756
1761
else :
1757
- if not len (bboxes2 ):
1758
- top = self .axes .bbox .ymax
1759
- else :
1760
- bbox = mtransforms .Bbox .union (bboxes2 )
1761
- top = bbox .y1
1762
+ try :
1763
+ spine = self .axes .spines ['top' ]
1764
+ spinebbox = spine .get_transform ().transform_path (
1765
+ spine .get_path ()).get_extents ()
1766
+ except KeyError :
1767
+ # use axes if spine doesn't exist
1768
+ spinebbox = self .axes .bbox
1769
+ bbox = mtransforms .Bbox .union (bboxes2 + [spinebbox ])
1770
+ top = bbox .y1
1771
+
1762
1772
self .label .set_position (
1763
1773
(x , top + self .labelpad * self .figure .dpi / 72.0 )
1764
1774
)
@@ -2043,29 +2053,37 @@ def set_label_position(self, position):
2043
2053
2044
2054
def _update_label_position (self , bboxes , bboxes2 ):
2045
2055
"""
2046
- Update the label position based on the sequence of bounding
2047
- boxes of all the ticklabels
2056
+ Update the label position based on the the bounding box enclosing
2057
+ all the ticklabels and axis spine
2048
2058
"""
2049
2059
if not self ._autolabelpos :
2050
2060
return
2051
2061
x , y = self .label .get_position ()
2052
2062
if self .label_position == 'left' :
2053
- if not len (bboxes ):
2054
- left = self .axes .bbox .xmin
2055
- else :
2056
- bbox = mtransforms .Bbox .union (bboxes )
2057
- left = bbox .x0
2063
+ try :
2064
+ spine = self .axes .spines ['left' ]
2065
+ spinebbox = spine .get_transform ().transform_path (
2066
+ spine .get_path ()).get_extents ()
2067
+ except KeyError :
2068
+ # use axes if spine doesn't exist
2069
+ spinebbox = self .axes .bbox
2070
+ bbox = mtransforms .Bbox .union (bboxes + [spinebbox ])
2071
+ left = bbox .x0
2058
2072
2059
2073
self .label .set_position (
2060
2074
(left - self .labelpad * self .figure .dpi / 72.0 , y )
2061
2075
)
2062
2076
2063
2077
else :
2064
- if not len (bboxes2 ):
2065
- right = self .axes .bbox .xmax
2066
- else :
2067
- bbox = mtransforms .Bbox .union (bboxes2 )
2068
- right = bbox .x1
2078
+ try :
2079
+ spine = self .axes .spines ['right' ]
2080
+ spinebbox = spine .get_transform ().transform_path (
2081
+ spine .get_path ()).get_extents ()
2082
+ except KeyError :
2083
+ # use axes if spine doesn't exist
2084
+ spinebbox = self .axes .bbox
2085
+ bbox = mtransforms .Bbox .union (bboxes2 + [spinebbox ])
2086
+ right = bbox .x1
2069
2087
2070
2088
self .label .set_position (
2071
2089
(right + self .labelpad * self .figure .dpi / 72.0 , y )
@@ -2158,8 +2176,8 @@ def get_ticks_position(self):
2158
2176
majt = self .majorTicks [0 ]
2159
2177
mT = self .minorTicks [0 ]
2160
2178
2161
- majorRight = ((not majt .tick1On ) and majt .tick2On
2162
- and (not majt .label1On ) and majt .label2On )
2179
+ majorRight = ((not majt .tick1On ) and majt .tick2On and
2180
+ (not majt .label1On ) and majt .label2On )
2163
2181
minorRight = ((not mT .tick1On ) and mT .tick2On and
2164
2182
(not mT .label1On ) and mT .label2On )
2165
2183
if majorRight and minorRight :
0 commit comments