@@ -2400,34 +2400,19 @@ def _update_label_position(self, renderer):
2400
2400
# get bounding boxes for this axis and any siblings
2401
2401
# that have been set by `fig.align_xlabels()`
2402
2402
bboxes , bboxes2 = self ._get_tick_boxes_siblings (renderer = renderer )
2403
-
2403
+ ax = self . axes
2404
2404
x , y = self .label .get_position ()
2405
+
2405
2406
if self .label_position == 'bottom' :
2406
- try :
2407
- spine = self .axes .spines ['bottom' ]
2408
- spinebbox = spine .get_window_extent ()
2409
- except KeyError :
2410
- # use Axes if spine doesn't exist
2411
- spinebbox = self .axes .bbox
2412
- bbox = mtransforms .Bbox .union (bboxes + [spinebbox ])
2413
- bottom = bbox .y0
2414
-
2415
- self .label .set_position (
2416
- (x , bottom - self .labelpad * self .figure .dpi / 72 )
2417
- )
2407
+ # Union with extents of the bottom spine if present, of the axes otherwise.
2408
+ bbox = mtransforms .Bbox .union (
2409
+ [* bboxes , ax .spines .get ("bottom" , ax ).get_window_extent ()])
2410
+ self .label .set_position ((x , bbox .y0 - self .labelpad * self .figure .dpi / 72 ))
2418
2411
else :
2419
- try :
2420
- spine = self .axes .spines ['top' ]
2421
- spinebbox = spine .get_window_extent ()
2422
- except KeyError :
2423
- # use Axes if spine doesn't exist
2424
- spinebbox = self .axes .bbox
2425
- bbox = mtransforms .Bbox .union (bboxes2 + [spinebbox ])
2426
- top = bbox .y1
2427
-
2428
- self .label .set_position (
2429
- (x , top + self .labelpad * self .figure .dpi / 72 )
2430
- )
2412
+ # Union with extents of the top spine if present, of the axes otherwise.
2413
+ bbox = mtransforms .Bbox .union (
2414
+ [* bboxes2 , ax .spines .get ("top" , ax ).get_window_extent ()])
2415
+ self .label .set_position ((x , bbox .y1 + self .labelpad * self .figure .dpi / 72 ))
2431
2416
2432
2417
def _update_offset_text_position (self , bboxes , bboxes2 ):
2433
2418
"""
@@ -2641,33 +2626,19 @@ def _update_label_position(self, renderer):
2641
2626
# get bounding boxes for this axis and any siblings
2642
2627
# that have been set by `fig.align_ylabels()`
2643
2628
bboxes , bboxes2 = self ._get_tick_boxes_siblings (renderer = renderer )
2629
+ ax = self .axes
2644
2630
x , y = self .label .get_position ()
2645
- if self .label_position == 'left' :
2646
- try :
2647
- spine = self .axes .spines ['left' ]
2648
- spinebbox = spine .get_window_extent ()
2649
- except KeyError :
2650
- # use Axes if spine doesn't exist
2651
- spinebbox = self .axes .bbox
2652
- bbox = mtransforms .Bbox .union (bboxes + [spinebbox ])
2653
- left = bbox .x0
2654
- self .label .set_position (
2655
- (left - self .labelpad * self .figure .dpi / 72 , y )
2656
- )
2657
2631
2632
+ if self .label_position == 'left' :
2633
+ # Union with extents of the left spine if present, of the axes otherwise.
2634
+ bbox = mtransforms .Bbox .union (
2635
+ [* bboxes , ax .spines .get ("left" , ax ).get_window_extent ()])
2636
+ self .label .set_position ((bbox .x0 - self .labelpad * self .figure .dpi / 72 , y ))
2658
2637
else :
2659
- try :
2660
- spine = self .axes .spines ['right' ]
2661
- spinebbox = spine .get_window_extent ()
2662
- except KeyError :
2663
- # use Axes if spine doesn't exist
2664
- spinebbox = self .axes .bbox
2665
-
2666
- bbox = mtransforms .Bbox .union (bboxes2 + [spinebbox ])
2667
- right = bbox .x1
2668
- self .label .set_position (
2669
- (right + self .labelpad * self .figure .dpi / 72 , y )
2670
- )
2638
+ # Union with extents of the right spine if present, of the axes otherwise.
2639
+ bbox = mtransforms .Bbox .union (
2640
+ [* bboxes2 , ax .spines .get ("right" , ax ).get_window_extent ()])
2641
+ self .label .set_position ((bbox .x1 + self .labelpad * self .figure .dpi / 72 , y ))
2671
2642
2672
2643
def _update_offset_text_position (self , bboxes , bboxes2 ):
2673
2644
"""
0 commit comments