@@ -25,16 +25,24 @@ def __repr__(self):
2525 )
2626
2727
28+ class SuppText (mtext .Text ):
29+ def __repr__ (self ):
30+ return "supptext: Custom Text({}, {}, {})" .format (
31+ self ._x , self ._y , repr (self ._text )
32+ )
33+
34+
2835def exp_text (
2936 exp = "" ,
3037 text = "" ,
38+ supp = "" ,
3139 loc = 0 ,
3240 * ,
3341 ax = None ,
3442 fontname = None ,
3543 fontsize = None ,
3644 exp_weight = "bold" ,
37- italic = (False , False ),
45+ italic = (False , False , False ),
3846 pad = 0 ,
3947):
4048 """Add typical LHC experiment primary label to the axes.
@@ -57,7 +65,7 @@ def exp_text(
5765 Defines size of "secondary label". Experiment label is 1.3x larger.
5866 exp_weight : string, optional
5967 Set fontweight of <exp> label. Default "bold".
60- italic : (bool, bool), optional
68+ italic : (bool, bool, bool ), optional
6169 Tuple of bools to switch which label is italicized
6270 pad : float, optional
6371 Additional padding from axes border in units of axes fraction size.
@@ -87,6 +95,14 @@ def exp_text(
8795 4 : {"xy" : (0.05 , 0.9550 - pad ), "va" : "bottom" },
8896 }
8997
98+ loc3_dict = {
99+ 0 : {"xy" : (1.012 , 1 + pad ), "va" : "top" , "ha" : "left" },
100+ 1 : {"xy" : (0.05 , 0.945 - pad ), "va" : "top" },
101+ 2 : {"xy" : (0.05 , 0.935 - pad ), "va" : "top" },
102+ 3 : {"xy" : (0.05 , 0.940 - pad ), "va" : "top" },
103+ 4 : {"xy" : (0.05 , 0.9450 - pad ), "va" : "top" },
104+ }
105+
90106 if loc not in [0 , 1 , 2 , 3 , 4 ]:
91107 raise ValueError (
92108 "loc must be in {0, 1, 2}:\n "
@@ -182,7 +198,52 @@ def dist(tup):
182198 )
183199 ax ._add_text (expsuffix )
184200
185- return exptext , expsuffix
201+ if loc == 0 :
202+ # No transformation, fixed location
203+ _t = mtransforms .offset_copy (exptext ._transform , units = "inches" , fig = ax .figure )
204+ elif loc == 1 :
205+ _t = mtransforms .offset_copy (
206+ exptext ._transform ,
207+ y = - exptext .get_window_extent ().height / _dpi ,
208+ units = "inches" ,
209+ fig = ax .figure ,
210+ )
211+ elif loc == 2 :
212+ _t = mtransforms .offset_copy (
213+ expsuffix ._transform ,
214+ y = - expsuffix .get_window_extent ().height / _dpi ,
215+ units = "inches" ,
216+ fig = ax .figure ,
217+ )
218+ elif loc == 3 :
219+ _t = mtransforms .offset_copy (
220+ expsuffix ._transform ,
221+ y = - expsuffix .get_window_extent ().height / _dpi ,
222+ units = "inches" ,
223+ fig = ax .figure ,
224+ )
225+ elif loc == 4 :
226+ _t = mtransforms .offset_copy (
227+ exptext ._transform ,
228+ y = - exptext .get_window_extent ().height / _dpi ,
229+ units = "inches" ,
230+ fig = ax .figure ,
231+ )
232+
233+ supptext = SuppText (
234+ * loc3_dict [loc ]["xy" ],
235+ text = supp ,
236+ transform = _t ,
237+ ha = loc3_dict [loc ].get ("ha" , "left" ),
238+ va = loc3_dict [loc ]["va" ],
239+ fontsize = _font_size / 1.3 ,
240+ fontname = fontname ,
241+ rotation = 0 if loc != 0 else 90 ,
242+ fontstyle = "italic" if italic [2 ] else "normal" ,
243+ )
244+ ax ._add_text (supptext )
245+
246+ return exptext , expsuffix , supptext
186247
187248
188249# Lumi text
@@ -234,6 +295,7 @@ def exp_label(
234295 * ,
235296 data = False ,
236297 label = "" ,
298+ pub = "" ,
237299 year = None ,
238300 lumi = None ,
239301 lumi_format = "{0}" ,
@@ -244,7 +306,7 @@ def exp_label(
244306 fontsize = None ,
245307 exp_weight = "bold" ,
246308 pad = 0 ,
247- italic = (False , False ),
309+ italic = (False , False , False ),
248310 ax = None ,
249311):
250312 """A convenience wrapper combining ``<exp>.text`` and ``lumitext`` providing for
@@ -283,7 +345,7 @@ def exp_label(
283345 Defines size of "secondary label". Experiment label is 1.3x larger.
284346 exp_weight : string, optional
285347 Set fontweight of <exp> label. Default "bold".
286- italic : (bool, bool), optional
348+ italic : (bool, bool, bool ), optional
287349 Tuple of bools to switch which label is italicized
288350 pad : float, optional
289351 Additional padding from axes border in units of axes fraction size.
@@ -321,16 +383,17 @@ def exp_label(
321383 if llabel is not None :
322384 _label = llabel
323385 else :
324- _label = ""
386+ _label = label
387+ if pub :
388+ _label = " " .join (["Supplementary" , _label ])
325389 if not data :
326- _label = " " .join (["Simulation" , label ])
327- else :
328- _label = label
390+ _label = " " .join (["Simulation" , _label ])
329391 _label = " " .join (_label .split ())
330392
331- exptext , expsuffix = exp_text (
393+ exptext , expsuffix , supptext = exp_text (
332394 exp = exp ,
333395 text = _label ,
396+ supp = pub if loc != 4 else "" , # Special handling for loc4
334397 loc = loc ,
335398 ax = ax ,
336399 fontname = fontname ,
@@ -341,8 +404,8 @@ def exp_label(
341404 )
342405 if loc == 4 :
343406 _t = mtransforms .offset_copy (
344- exptext ._transform ,
345- y = - exptext .get_window_extent ().height / ax .figure .dpi ,
407+ supptext ._transform ,
408+ y = - supptext .get_window_extent ().height / ax .figure .dpi ,
346409 units = "inches" ,
347410 fig = ax .figure ,
348411 )
@@ -356,16 +419,35 @@ def exp_label(
356419 * exptext .get_position (),
357420 text = rlabel if rlabel is not None else _lumi ,
358421 transform = _t ,
359- ha = exptext .get_ha (),
422+ ha = supptext .get_ha (),
360423 va = "top" ,
361424 fontsize = fontsize ,
362425 fontname = fontname ,
363426 fontstyle = "normal" ,
364427 )
365428 ax ._add_text (explumi )
366- return exptext , expsuffix , explumi
367429
368- return exptext , expsuffix
430+ _t = mtransforms .offset_copy (
431+ explumi ._transform ,
432+ y = - explumi .get_window_extent ().height / ax .figure .dpi ,
433+ units = "inches" ,
434+ fig = ax .figure ,
435+ )
436+ _font_size = rcParams ["font.size" ] if fontsize is None else fontsize
437+ supptext = SuppText (
438+ * explumi .get_position (),
439+ text = pub ,
440+ transform = _t ,
441+ ha = explumi .get_ha (),
442+ va = "top" ,
443+ fontsize = _font_size / 1.3 ,
444+ fontname = fontname ,
445+ fontstyle = "italic" if italic [2 ] else "normal" ,
446+ )
447+ ax ._add_text (supptext )
448+ return exptext , expsuffix , supptext , explumi
449+
450+ return exptext , expsuffix , supptext
369451
370452
371453def savelabels (
0 commit comments