Calculating correct margin for plotting histogram

Dear ROOT users and developers,

is there any way to calculate how large of a margin does one need to set via TCanvas::SetMarginLeft and TCanvas::SetMarginRight when using pixel fonts (e.g. font 83)?


maybe @bellenot or @couet can help :slight_smile:


Maybe it is related to this topic?

Cheers, Bertrand.

How large for what ? do you have a small example showing the problem you encounter ?

This is more or less typical plot: . The size of the pad is calculated automatically depending on the number of runs and channels, with a fixed minimum size 800*600. If the plot is tall (height >> width), the vertical margins become crazy, and the horizontal ones are fine

The plot you showed seems correct. Do you have a small reproducer showing the “craziness” of the plot ?

(takes 2 command-line arguments: number of bins on X and Y axes).

Plots:, created with:

hist2dtest 20 20
hist2dtest 20 200
hist2dtest 200 20
hist2dtest 200 200

What I don’t like is how huge the margins look on non-square images (esp. on 20x200 one)

I see … you can simply reduce them with SetMargin ? …

And that’s what I’m talking about: is there a way to calculate (not empirically guess) the values for SetMargin depending on the nx and ny values?

“Empyrically guessing” is writing code like this

if nx > 10 and nx < 20:
  margin_x = 0.5
else if nx > 20 and nx < 50:
  margin_y = 0.027

No, there is no automatic way.,

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.