@@ -2400,34 +2400,18 @@ 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
-
2404
2403
x , y = self .label .get_position ()
2404
+
2405
2405
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
- )
2406
+ # Union with extents of the bottom spine if present, of the axes otherwise.
2407
+ bbox = mtransforms .Bbox .union ([
2408
+ * bboxes , self .axes .spines .get ("bottom" , self .axes ).get_window_extent ()])
2409
+ self .label .set_position ((x , bbox .y0 - self .labelpad * self .figure .dpi / 72 ))
2418
2410
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
- )
2411
+ # Union with extents of the top spine if present, of the axes otherwise.
2412
+ bbox = mtransforms .Bbox .union ([
2413
+ * bboxes2 , self .axes .spines .get ("top" , self .axes ).get_window_extent ()])
2414
+ self .label .set_position ((x , bbox .y1 + self .labelpad * self .figure .dpi / 72 ))
2431
2415
2432
2416
def _update_offset_text_position (self , bboxes , bboxes2 ):
2433
2417
"""
@@ -2642,32 +2626,17 @@ def _update_label_position(self, renderer):
2642
2626
# that have been set by `fig.align_ylabels()`
2643
2627
bboxes , bboxes2 = self ._get_tick_boxes_siblings (renderer = renderer )
2644
2628
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
2629
2630
+ if self .label_position == 'left' :
2631
+ # Union with extents of the left spine if present, of the axes otherwise.
2632
+ bbox = mtransforms .Bbox .union ([
2633
+ * bboxes , self .axes .spines .get ("left" , self .axes ).get_window_extent ()])
2634
+ self .label .set_position ((bbox .x0 - self .labelpad * self .figure .dpi / 72 , y ))
2658
2635
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
- )
2636
+ # Union with extents of the right spine if present, of the axes otherwise.
2637
+ bbox = mtransforms .Bbox .union ([
2638
+ * bboxes2 , self .axes .spines .get ("right" , self .axes ).get_window_extent ()])
2639
+ self .label .set_position ((bbox .x1 + self .labelpad * self .figure .dpi / 72 , y ))
2671
2640
2672
2641
def _update_offset_text_position (self , bboxes , bboxes2 ):
2673
2642
"""
0 commit comments