TCanvas::Divide(Int_t n)

I often face the problem of dividing a TCanvas in a reasonable way so that it can host an unknown number n of plots. My usual solution is the following:

int w = ceil(sqrt(n));
int h = round(sqrt(n));

TCanvas *c = new TCanvas();

Since I believe this is a very common problem I’d suggest you to add a TCanvas::Divide(Int_t n) function that does something similar.

That s a nice simple way to do it.
As it is so simple do you think it is worth adding a new signature ?
May be yes…
I guess the others parameters of Divide() are not needed ?

If you do this … please always take into account the actual “width” and “height” of the canvas (i.e. its “aspect ratio”).
In other words, a “portrait” orientation should result in a different division than a “landscape” orientation. The more “landscape” the actual canvas is, the more columns should be there (and fewer rows) and vice versa, the more “portrait” the actual canvas is, the more rows should be there (and fewer columns).
So, in the two “extreme cases” you would have a single row with “n” columns and a single column with “n” rows.
Also, one should maybe set the margins between sub-pads to 0 (unless you leave the other parameters of Divide as they are now).


I would appreciate to have such a method. I calculate it the same way.
The extra complexity proposed by Pepe would be lovely but is not a necessity for me.


Actually there is an issue with the name “Divide”…
The current Divide(…) method having all its parameters defaulted, the call with a single integer is already valid, therefore we get a message like …

error: call to member function ‘Divide’ is ambiguous

… from the compiler.
So we have to call it another way. I suggest DivideSqrt(n). What do you think ?

Or DivideSquare(n) …

I have implemented DivideSquare.
Now in the SVN trunk.

Thank you