13
13
from ..utils import (
14
14
bbox_in_figure_space ,
15
15
get_transPanels ,
16
+ rel_position ,
16
17
tight_bbox_in_figure_space ,
17
18
)
18
19
@@ -534,9 +535,9 @@ def horizontally_align_text(
534
535
"center" : 0.5 ,
535
536
"right" : 1.0 ,
536
537
}
537
- f = lookup [ha ]
538
+ rel = lookup [ha ]
538
539
else :
539
- f = ha
540
+ rel = ha
540
541
541
542
if how == "panel" :
542
543
left = spaces .l .left
@@ -546,7 +547,7 @@ def horizontally_align_text(
546
547
right = spaces .r .plot_right
547
548
548
549
width = spaces .items .calc .width (text )
549
- x = left * ( 1 - f ) + ( right - width ) * f
550
+ x = rel_position ( rel , width , left , right )
550
551
text .set_x (x )
551
552
text .set_horizontalalignment ("left" )
552
553
@@ -571,9 +572,9 @@ def vertically_align_text(
571
572
"center_baseline" : 0.5 ,
572
573
"bottom" : 0.0 ,
573
574
}
574
- f = lookup [va ]
575
+ rel = lookup [va ]
575
576
else :
576
- f = va
577
+ rel = va
577
578
578
579
if how == "panel" :
579
580
top = spaces .t .top
@@ -583,7 +584,7 @@ def vertically_align_text(
583
584
bottom = spaces .b .plot_bottom
584
585
585
586
height = spaces .items .calc .height (text )
586
- y = bottom * ( 1 - f ) + ( top - height ) * f
587
+ y = rel_position ( rel , height , bottom , top )
587
588
text .set_y (y )
588
589
text .set_verticalalignment ("bottom" )
589
590
@@ -619,32 +620,42 @@ def set_position(
619
620
aob .set_bbox_to_anchor (anchor_point , transform ) # type: ignore
620
621
621
622
if legends .right :
622
- j = legends .right .justification
623
- y = (
624
- params .bottom * (1 - j )
625
- + (params .top - spaces .r ._legend_height ) * j
623
+ y = rel_position (
624
+ legends .right .justification ,
625
+ spaces .r ._legend_height ,
626
+ params .bottom ,
627
+ params .top ,
626
628
)
627
629
x = spaces .r .x2 ("legend" )
628
630
set_position (legends .right .box , (x , y ), (1 , 0 ))
629
631
630
632
if legends .left :
631
- j = legends .left .justification
632
- y = (
633
- params .bottom * (1 - j )
634
- + (params .top - spaces .l ._legend_height ) * j
633
+ y = rel_position (
634
+ legends .left .justification ,
635
+ spaces .l ._legend_height ,
636
+ params .bottom ,
637
+ params .top ,
635
638
)
636
639
x = spaces .l .x1 ("legend" )
637
640
set_position (legends .left .box , (x , y ), (0 , 0 ))
638
641
639
642
if legends .top :
640
- j = legends .top .justification
641
- x = params .left * (1 - j ) + (params .right - spaces .t ._legend_width ) * j
643
+ x = rel_position (
644
+ legends .top .justification ,
645
+ spaces .t ._legend_width ,
646
+ params .left ,
647
+ params .right ,
648
+ )
642
649
y = spaces .t .y2 ("legend" )
643
650
set_position (legends .top .box , (x , y ), (0 , 1 ))
644
651
645
652
if legends .bottom :
646
- j = legends .bottom .justification
647
- x = params .left * (1 - j ) + (params .right - spaces .b ._legend_width ) * j
653
+ x = rel_position (
654
+ legends .bottom .justification ,
655
+ spaces .b ._legend_width ,
656
+ params .left ,
657
+ params .right ,
658
+ )
648
659
y = spaces .b .y1 ("legend" )
649
660
set_position (legends .bottom .box , (x , y ), (0 , 0 ))
650
661
@@ -680,17 +691,17 @@ def set_plot_tag_position(tag: Text, spaces: LayoutSpaces):
680
691
}
681
692
682
693
if isinstance (position , str ):
683
- # Coordinates of the space to place the tag
694
+ # Coordinates of the space in which to place the tag
684
695
if location == "plot" :
685
696
(x1 , y1 ), (x2 , y2 ) = spaces .plot_area_coordinates
686
697
else :
687
698
(x1 , y1 ), (x2 , y2 ) = spaces .panel_area_coordinates
688
699
689
700
# Calculate the position when the tag has no margins
690
- fx , fy = lookup [position ]
701
+ rel_x , rel_y = lookup [position ]
691
702
width , height = spaces .items .calc .size (tag )
692
- x = x1 * ( 1 - fx ) + ( x2 - width ) * fx
693
- y = y1 * ( 1 - fy ) + ( y2 - height ) * fy
703
+ x = rel_position ( rel_x , width , x1 , x2 )
704
+ y = rel_position ( rel_y , height , y1 , y2 )
694
705
695
706
# Adjust the position to account for the margins
696
707
# When the units for the margin are in the figure coordinates,
0 commit comments