Home | News | Documentation | Download

Plotting axis ticks at 0.1 level in log scale

Dear experts,

Hope you are doing well!

I am writing to see if there is a way to plot axis ticks with a precision of 0.1 when that axis is set to log scale? For example, in a range from 0.5 to 10, plotting ticks at 0.6, 0.7,…, 1.1, 1.2, …, 2.1,2.2,…?

Thanks a lot!

Hi,

Try this:

{  
  TCanvas *c = new TCanvas;
  c->SetLogx();
  TH1 * h = new TH1F("h", "h", 50, 0.5, 10);
  h -> GetXaxis() -> SetMoreLogLabels();
  h->Draw();
}

You should see:

If you compiled ROOT with -Dwebgui=on -DCMAKE_CXX_VERSION=14, you also can use root --web macro.C. In this case JSROOT used for rendering and it provides output:

Canvas

Regards,
Sergey

Hi Sergey,

Thanks for your reply! But I guess what I want is more ticks, rather than labels. Like this:

image

Thanks a lot!
Sebastian

Hi Sebastian,

Probably we should ask our expert @couet if more ticks can be drawn on log scale.
There is method gStyle->SetNdivisions(510, "x");, but seems to be it has no effect for log scale.
If you just need to produce image file, you can draw TLine and TText objects at required places.

Regards,
Sergey

thanks for the information.

Dear Sergey,

Ah in the end I manually calculated the position of the sub-ticks and plotted them… It seems to be the only way to do this unfortunately, but it works :smiley:

Thanks a lot!
Sebastian

1 Like

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