Dear experts,
Is it possible to change the position of a TLegend (or any TPave object) after construction? I want to be able to construct a TLegend, fill it, then set its position (and size if possible) relative to the margins of my histogram. For instance:
: m_Legend(0.3, 0.15, "", "NBNDC") // in some initializer list
// by specifying just width and height and assuming automatic positioning
or
: m_Legend(0, 0, 0, 0, "", "NBNDC") // or specifying zero size and changing it later
then later on, before drawing
TStyle *s = gROOT->GetStyle("ATLAS");
float leftMargin = s->GetPadLeftMargin();
float topMargin = s->GetPadTopMargin();
m_Legend.SetX1NDC(leftMargin+0.02);
m_Legend.SetX2NDC(leftMargin+0.02+0.3); // or just set x1,y1 and rely on width and height of TLegend
m_Legend.SetY1NDC(1-topMargin-0.02-0.15);
m_Legend.SetY2NDC(1-topMargin-0.02);
m_Legend.Draw(); // legend isn't drawn with the new x1, x2, y1, y2 --
// neither with the automatic positioning, or with zero size, depending on construction
// I also tried m_Legend.DrawPave(x1,...)
// draw other objects with option "SAME"
c.Update();
c.Print(...);
I think I’m seeing the same problem as detailed here: TPaveText position before drawing
If there is a better way to programmatically set the positions of objects relative to the margins of a histogram, please let me know. Restricting the automatic positioning to upper left or upper right would also be sufficient.
Thanks,
Justin