TGaxis()::SetMaxDigits not working as expected

Would you like to be able to use the printf() convention to format numerical axis labels (labels not titles)?

  • Yes
  • No
  • Don’t Care

0 voters

Hi,

I’m trying to use TGaxis::SetMaxDigits() to restrict the number of digits displayed on the vertical axis of a 1D histogram. I call the function in my root logon file to set the maximum to 2. But it doesn’t work properly in all cases. See the attached figure, as well as the macro used to produce it and my rootlogon.C. It needs to chose an exponent 1e3 but won’t do so. Turning exponents off is not satisfactory. The numbers are too long. It looks silly. I could obviously modify the normalisation of the figure but for plot uniformity we want to see events/unit not events/10unit. Actually, the general solution is to allow users to set the format as in, say, printf().

Regards,

mike
rootlogon_for_root.C (3.76 KB)
max_digit_prob.C (108 Bytes)

You must be careful when using SetMaxDigits. In case the setting forces an exponent, you may not get what you request because we force (following many requests) only 10^N with N being a multiple of 3.
In your particular example, calling SetMaxDigits(3) will work correctly.
I also strongly suggest to get rid of your extremely UGLY settings ::slight_smile:

Back to your poll, it is ambiguous.
-a general setting with a printf is a total non-sense. You cannot apply
a printf setting to all the plots. Remember that plotting in ROOT is not
a sequential operation !

-a setting specific to an axis will be a very expensive operation as it will
require to add 3 TStrings (or equivalent) to a TH1 object. I am not sure that the majority will agree with your request if they know the price to pay.

-You should use the graphics editor to customize very special cases like
the bad setting of your example, but there is no point in using the graphics editor if you start by destroying all possible optimisations with bad settings as in your case.

Rene

Yes it does. I’m a bit confused by what SetMaxDigits does. With SetMaxDigits(3) I get a plot with two digits along the vertical scale, but with SetMaxDigits(2) I get 4! Here is what the html documenation says:

But, SetMaxDigits does something more than this as there is a 10^N with both 3 and 2.

Well, the style is intended to approximate PAW’s default which people, particularly more senior people, seem to like. Seriously, when I used to show plots in the ROOT default style people would complain that they couldn’t see the labels and wonder if something was wrong with the projector as it looked kind of dim! :slight_smile:

I don’t think I understand the bit about “sequential operation”. But, maybe my question wasn’t very clear. I’d like to be able to request a certain number of significant digits as one can do in, say, printf. Why is this nonsense? I’d be happy with:

1e3 -|
5e2 -|
0e0 -|--------->

or maybe I’d like to choose it like this:

1.0e3 -|
5.0e2 -|
0.0e0 -|-------->

As far as I can tell, this will work for the vast majority of my cases. I might in some extreme case have to write “Ne1XX” rather than “NeX” which could cause my label to merge with my title (this is the major thing I am trying to avoid), but I’ll never have to write “NeXXXXX” as it’ isn’t physical.

Can’t it work in a global fashion, like SetMaxDigit ? Or the time formatting? Maybe formatting options could be stored in fChopt? Or, how about this: store the formatting instructions in fTimeFormat. If TAxis::fTimeDisplay is true then options are interpreted as time formatting. If fTimeFormat is false then options are interpreted as numerical axis formatting. Wouldn’t this work?

mike

I suggest you to mention that the power N of 10^N described in the documentation TGaxis::SetMaxDigits would be a multiple of 3. I met the issue as well and did not find any explanation on the documentation. It may help us to use the function correctly and avoid the unexpected errors. Thanks!

1 Like