Resize a TFrame via code

I need to resize the TFrame of the histograms and graphs (TH1 and TGraph) created into a canvas. I need to do this with the methods of the classes, but I have not found anything. I need to resize the TFrame because I need to add some labels in the right side of the canvas that contains the histogram.

How is it possible to do this?

Thank you very much

Best regards

Andrea Bulgarelli

TFrame derives from TBox (see the doc at, and TBox has the methods SetX1, SetX2, and Y1, SetY2. Use those.

I have tried the following commands

TCanvas c1;
TH1D h1(“A”, “B”, 100, 0, 100);
TFrame* f = (TFrame*) c1.FindObject(“TFrame”);


It print 100. After this


but it don’t work, because when a make an update of the canvas (i.e. with the mouse or with the c1.Modified(); c1.Update()) the are no resize of the frame and with f->GetX2() I obtain 100.

I have tried also with f->Draw() but the result is the same.

Thank you for your help.

Best regards
Andrea Bulgarelli

Hi Andrea,

try gPad::SetTop|Bottom|Left|RightMargin().


it is really a trick with the margins !! But it seems to me to be ‘displayed histogram’ dependent. Does there exist a way to position it relatively in 0-1 region? Or one must first check the histogram ranges and then compute all the ranges and apply them… ?
thak you,

I think the simple way is to create your own GUI based on either ROOT or Qt class libraries with the embedded TCanvas.

As soon as you satisfy “One histogram - one TCanvas” you may have placed and layouted the embedded TCanvas’ using the advanced GUI layout mechanzin rather the primitive TFrame manipulation.