diff --git a/src/mplhep/label.py b/src/mplhep/label.py index 6e1d0189..e3e9640f 100644 --- a/src/mplhep/label.py +++ b/src/mplhep/label.py @@ -49,6 +49,8 @@ def exp_text( - 1 : Top left corner - 2 : Top left corner, multiline - 3 : Split EXP above axes, rest of label in top left corner" + - 4 : Top left corner, inside the frame + - 5 : Top right corner, inside the frame ax : matplotlib.axes.Axes, optional Axes object (if None, last one is fetched) fontname : string, optional @@ -77,6 +79,7 @@ def exp_text( loc1_dict = { 0: {"xy": (0.001, 1 + pad), "va": "bottom"}, 1: {"xy": (0.05, 0.95 - pad), "va": "top"}, + 2: {"xy": (0.56, 0.95 - pad), "va": "top"}, } loc2_dict = { @@ -85,15 +88,18 @@ def exp_text( 2: {"xy": (0.05, 0.9450 - pad), "va": "top"}, 3: {"xy": (0.05, 0.95 - pad), "va": "top"}, 4: {"xy": (0.05, 0.9550 - pad), "va": "bottom"}, + 5: {"xy": (0.5650, 0.9550 - pad), "va": "bottom"}, } - if loc not in [0, 1, 2, 3, 4]: + if loc not in [0, 1, 2, 3, 4, 5]: raise ValueError( - "loc must be in {0, 1, 2}:\n" + "loc must be in {0, 1, 2, 3, 4, 5}:\n" "0 : Above axes, left aligned\n" "1 : Top left corner\n" "2 : Top left corner, multiline\n" "3 : Split EXP above axes, rest of label in top left corner\n" + "4 : Top left corner, inside the frame \n" + "5 : Top right corner, inside the frame \n" ) def pixel_to_axis(extent, ax=None): @@ -119,6 +125,8 @@ def dist(tup): if loc in [0, 3]: _exp_loc = 0 + elif loc == 5: + _exp_loc = 2 else: _exp_loc = 1 _formater = ax.get_yaxis().get_major_formatter() @@ -152,7 +160,7 @@ def dist(tup): _t = mtransforms.offset_copy( exptext._transform, x=_exp_xoffset, units="inches", fig=ax.figure ) - elif loc in [1, 4]: + elif loc in [1, 4, 5]: _t = mtransforms.offset_copy( exptext._transform, x=_exp_xoffset, @@ -256,8 +264,9 @@ def exp_label( - 0 : Above axes, left aligned - 1 : Top left corner - 2 : Top left corner, multiline - - 3 : Split EXP above axes, rest of label in top left corner" + - 3 : Split EXP above axes, rest of label in top left corner - 4 : (1) Top left corner, but align "rlabel" underneath + - 5 : (1) Top right corner, but align "rlabel" underneath ax : matplotlib.axes.Axes, optional Axes object (if None, last one is fetched) data : bool, optional @@ -339,7 +348,7 @@ def exp_label( italic=italic, pad=pad, ) - if loc == 4: + if loc >= 4: _t = mtransforms.offset_copy( exptext._transform, y=-exptext.get_window_extent().height / ax.figure.dpi, diff --git a/tests/baseline/test_label_loc.png b/tests/baseline/test_label_loc.png index bceb6ebd..80611aa5 100644 Binary files a/tests/baseline/test_label_loc.png and b/tests/baseline/test_label_loc.png differ diff --git a/tests/test_styles.py b/tests/test_styles.py index fdc2d31c..56fd4b21 100644 --- a/tests/test_styles.py +++ b/tests/test_styles.py @@ -214,7 +214,7 @@ def test_labeltext_loc(): @pytest.mark.mpl_image_compare(style="default") def test_label_loc(): - fig, axs = plt.subplots(1, 5, figsize=(20, 4)) + fig, axs = plt.subplots(2, 3, figsize=(20, 4)) for i, ax in enumerate(axs.flatten()): hep.cms.label("Preliminary", loc=i, ax=ax, lumi=50, data=True) return fig