Resize canvas to get real aspect ratio of TH2 or TGraph

Thanks for your comments.

No, the function sets the REAL aspect ratio, i.e what you would see in reality, if axes x and y are in mm. If my histogram is from 0 to 1 in x and 0 to 2 in y, I call the function, which looks automatically at the axes lengths and infers that you need an aspect ratio of 2:1 to have a PROPORTIONAL representation of reality. If my axes are from 0.234 to 0.586 and y from 2.189 and 3.679, I do not want to bother what should be the aspect ratio, I just want that it is the “real” one, and the function does it for me. So no need for calculating previously the ratio and passing it as argument.

Of course, one could think of another function that sets not a real, but a desired aspect ratio. I would however separate them clearly by name.

SetRealAspectRatio();//Resizes your canvas so that unit lengths in x and y occupy same number of pixels
SetFrameAspectRatio(factor);//Resizes your canvas so that the number of pixels of your x axis is "factor" times your y axis (in n of pixels)

And each function should be implemented differently. I could provide a code suggestion for the second type.

Yes, that’s a good idea, an extra (defaulted) parameter like SetRealAspectRatio(const Int_t axis=1)

Good point. I will think about it by using the c->SetTop|Bottom|Left|RightMargin() function, i.e. modifying the actual frame size inside the subpad, as the size of the subpad itself should not be modified.