Home | News | Documentation | Download

Calculating correct margin for plotting histogram


#1

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)?

Thanks,
Ivan


#2

Hi,
maybe @bellenot or @couet can help :slight_smile:


#3

Hi,

Maybe it is related to this topic?

Cheers, Bertrand.


#4

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


#5

This is more or less typical plot: http://imgur.com/a/IdzRT . 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


#6

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


#7

Code: https://gist.github.com/iarspider/4fb3645cd012d179e6f578c3ba09cdba
(takes 2 command-line arguments: number of bins on X and Y axes).

Plots: http://imgur.com/a/1B2NS, 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)


#8

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


#9

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
else:
  ...

#10

No, there is no automatic way.,


#11

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