Automated TLegend positioning

Hi All,

I am getting fed up of specifying the position of my legend and having it overlap data-points when some property of my data changes.

Here is a thought: How hard would it be to ask “How many datapoints does this legend placement overlap?” ? Preferably without doing the math inside my macro, since presumably I would have to emulate lots of ROOT subtleties and things like error bars, the log state… I also assume I am not the first to think of this as a concept. Is there prior art?

I already have a macro which allows me to specify as a parameter “XY” where X=“LCR” and Y=“MBR”. It would be ideal if I could automatically try these in turn and take the one that overlaps the least points. I’m guessing this is non-trivial to compute though, especially to come to agreement with ROOT from outside ROOT.

Another thing I will do is to place the legend outside the plot, but often the plots do contain lots of space, so it would be good to place the legend inside.

Thanks in advance,

  • Peter

TLegend inherits from TBox which has the method IsInside (in the svn trunk):
If you loop over this method with your data points you will be able to know how many data points are in the TLegend.

Is there a method for converting from plot co-ordinates to pad co-ordinates or vice versa? (I assume the box uses pad co-ordinates, 0. to 1. ?). I guess I would also want an overlaps() function which tells me if it overlaps a rectangle, so I can easily account for error bars.

See all the to methods here (XtoPad, etc …):

Thanks couet.