@@ -1581,8 +1581,8 @@ def set_ticks(self, ticks, minor=False):
15811581
15821582 def _update_label_position (self , bboxes , bboxes2 ):
15831583 """
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
15861586 """
15871587 raise NotImplementedError ('Derived must override' )
15881588
@@ -1737,28 +1737,38 @@ def set_label_position(self, position):
17371737
17381738 def _update_label_position (self , bboxes , bboxes2 ):
17391739 """
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
17421742 """
17431743 if not self ._autolabelpos :
17441744 return
17451745 x , y = self .label .get_position ()
17461746 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+
17521757 self .label .set_position (
17531758 (x , bottom - self .labelpad * self .figure .dpi / 72.0 )
17541759 )
17551760
17561761 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+
17621772 self .label .set_position (
17631773 (x , top + self .labelpad * self .figure .dpi / 72.0 )
17641774 )
@@ -2043,29 +2053,37 @@ def set_label_position(self, position):
20432053
20442054 def _update_label_position (self , bboxes , bboxes2 ):
20452055 """
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
20482058 """
20492059 if not self ._autolabelpos :
20502060 return
20512061 x , y = self .label .get_position ()
20522062 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
20582072
20592073 self .label .set_position (
20602074 (left - self .labelpad * self .figure .dpi / 72.0 , y )
20612075 )
20622076
20632077 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
20692087
20702088 self .label .set_position (
20712089 (right + self .labelpad * self .figure .dpi / 72.0 , y )
@@ -2158,8 +2176,8 @@ def get_ticks_position(self):
21582176 majt = self .majorTicks [0 ]
21592177 mT = self .minorTicks [0 ]
21602178
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 )
21632181 minorRight = ((not mT .tick1On ) and mT .tick2On and
21642182 (not mT .label1On ) and mT .label2On )
21652183 if majorRight and minorRight :
0 commit comments