Set histogram x axis digit number

ROOT Version: 6.12/06
Platform: macOS
Compiler: Not Provided

I’m trying controlling a histogram x axis digit numbers through hist->GetXaxis()->SetMaxDigits() or TGaxis gx = (TGaxis)hist->GetXaxis();gx->SetMaxDigits(); but only y axis takes effect even I get the x axis. Any way to set x axis digit number?
For example, I want to set the x axis 1.4 \times 10^-5 instead of 14 \times 10^-6
dyStats.pdf (14.4 KB)

@mhstar maybe this post can be helpful for you TGaxis::SetMaxDigits ?

Do you have a small reproducer showing this effect ?

the axis labeling algorithm seems to allow only
“natural” exponents: e-3, e-6, e-9 etc
Try with the following:

root [13] auto h3 = new TH1F("hh3", "h3h", 100, 14e-4, 16e-4);
root [14] auto ax3 = h3->GetXaxis()
(TAxis *) @0x7ffdccdec1d8
root [15] h3->Draw()
root [16] ax3->SetMaxDigits(3)
root [17] ax3->SetMaxDigits(5)
root [18] ax3->SetMaxDigits(4)

(root 6.14.00)

Yes it works that way…

No, it doesn’t help. The way still works only for y axis not x axis.

Here I provide the data root file and the script to produce the plot. Thanks.
dyStats.cpp (3.1 KB)
dyStats.root (54.6 KB)

I try this, but it still works only for y axis not for x axis. Maybe it’s because I use root 6.12/06 version but you use root 6.14.00(which I noticed from your post)?
Anyway, I provide the data and the script to produce the graph, which makes your help more direct and convenient. Thank you.
dyStats.cpp (3.1 KB)
dyStats.root (54.6 KB)

with 6.15 (master) you macro gives me the following output. So the exponents are on the X axis.

Yes, that’s what I get too. I want to get x axis with order 10^-5 instead of 10^-6. That’s I’m trying to set the max digit of x axis. It’s the right way to get this by setting x axis max digit number?

Can you try it again after you uncomment line 95-96 to see the x axis takes effect or not? It takes effect on y axis which is very weird for me.

Why are you using a TExec ?

No, I don’t use that. That’s just a try from another suggestion, but it gives the same result which only takes effect on y axis too not on x axis.

Ok I simplified your macro to concentrate only on the axis topic. I ended up with this:

void dyStats(){
   TCanvas *cc = new TCanvas("cc","cc",1000,600);
   auto f = new TFile("dyStats.root");

   auto cross = new TH1F("cross","cross",100,1.4e-5,1.57e-5);
   TTree* cs = (TTree*)f->Get("dyStats");

   cross->SetXTitle("cross section(mb)");

I gave more freedom on the X axis (7 digits so the exponent disappeared) and less on the Y axis (only one digits so the exponent appear). The important thing to notice is that you are able to act on both axis independently .

1 Like

Could you test whether it works for cross->GetXaxis()->SetMaxDigits(2); that’s my ultimate goal.

Dear mhstar,

I am afraid you did not get the basics of my post:
The implemented algorithm c a n n o t produce
exponents like : 10-5, 10-2
only 10-3, 10-6, 10-9 etc
for whatever axis


Now I think I understand TGaxis::SetMaxDigits(). Thank you.

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