@@ -830,7 +830,10 @@ def set_plot_tag_position(tag: Text, spaces: LayoutSpaces):
830
830
831
831
def set_plot_tag_position_in_margin (tag : Text , spaces : LayoutSpaces ):
832
832
"""
833
- Place the tag in the margin around the plot
833
+ Place the tag in an inner margin around the plot
834
+
835
+ The panel_margin remains outside the tag. For compositions, the
836
+ tag is placed and within the tag_alignment space.
834
837
"""
835
838
position : TagPosition = spaces .plot .theme .getp ("plot_tag_position" )
836
839
if not isinstance (position , str ):
@@ -840,18 +843,34 @@ def set_plot_tag_position_in_margin(tag: Text, spaces: LayoutSpaces):
840
843
)
841
844
842
845
tag .set_position (spaces .to_figure_space ((0.5 , 0.5 )))
843
- if "top" in position :
844
- tag .set_y (spaces .t .y2 ("plot_tag" ))
845
- tag .set_verticalalignment ("top" )
846
- if "bottom" in position :
847
- tag .set_y (spaces .b .y1 ("plot_tag" ))
848
- tag .set_verticalalignment ("bottom" )
849
- if "left" in position :
850
- tag .set_x (spaces .l .x1 ("plot_tag" ))
846
+ ha = spaces .plot .theme .get_ha ("plot_tag" )
847
+ va = spaces .plot .theme .get_va ("plot_tag" )
848
+ if "left" in position : # left, topleft, bottomleft
849
+ space = spaces .l .tag_alignment
850
+ x = spaces .l .x1 ("plot_tag" ) - (1 - ha ) * space
851
+ tag .set_x (x )
851
852
tag .set_horizontalalignment ("left" )
852
- if "right" in position :
853
- tag .set_x (spaces .r .x2 ("plot_tag" ))
854
- tag .set_horizontalalignment ("right" )
853
+ if "right" in position : # right, topright, bottomright
854
+ space = spaces .r .tag_alignment
855
+ x = spaces .r .x1 ("plot_tag" ) + ha * space
856
+ tag .set_x (x )
857
+ tag .set_horizontalalignment ("left" )
858
+ if "bottom" in position : # bottom, bottomleft, bottomright
859
+ space = spaces .b .tag_alignment
860
+ y = spaces .b .y1 ("plot_tag" ) + (1 - va ) * space
861
+ tag .set_y (y )
862
+ tag .set_verticalalignment ("bottom" )
863
+ if "top" in position : # top, topleft, topright
864
+ space = spaces .t .tag_alignment
865
+ y = spaces .t .y1 ("plot_tag" ) + va * space
866
+ tag .set_y (y )
867
+ tag .set_verticalalignment ("bottom" )
868
+
869
+ justify = TextJustifier (spaces )
870
+ if position in ("left" , "right" ):
871
+ justify .vertically_along_plot (tag , va )
872
+ elif position in ("top" , "bottom" ):
873
+ justify .horizontally_across_plot (tag , ha )
855
874
856
875
857
876
def _plot_tag_margin_adjustment (
0 commit comments