How about this: [code]void testLogx()
{
// Prepare dummy histograms
//----------------------------------------------------------------------------
Double_t xlow = 99.999;
Double_t xup = 400.01; // try 400.01 or 150.01
Int_t nbinsx = Int_t(xup - xlow);
TF1* f1 = new TF1(“f1”, “gaus(0)”, xlow, xup);
f1->SetParameter(0, 1);
f1->SetParameter(1, 0.50 * (xup + xlow));
f1->SetParameter(2, 0.25 * (xup - xlow));
TH1F* h1 = new TH1F(“h1”, “h1”, nbinsx, xlow, xup);
TH1F* h2 = new TH1F(“h2”, “h2”, nbinsx, xlow, xup);
h1->FillRandom(“f1”, 10000);
h2->FillRandom(“f1”, 10000);
// Draw the first canvas
//----------------------------------------------------------------------------
TCanvas* c1 = new TCanvas(“c1”, “c1”, 15, 50, 700, 500);
c1->SetLogx();
c1->SetLogy();
h1->Draw();
c1->Update();
Float_t uxmin = c1->GetUxmin();
Float_t uxmax = c1->GetUxmax();
Float_t uymin = c1->GetUymin();
// x-axis ticks
//----------------------------------------------------------------------------
if (c1->GetLogx()) {
h1->GetXaxis()->SetNdivisions(0);
TLine tick;
tick.SetLineWidth(1);
tick.SetLineColor(1);
Float_t length = (c1->GetLogy()) ? 0.2 : 2.0;
for (Int_t i=xlow; i<=xup; i+=10) {
Float_t xx = i;
if (c1->GetLogy())
tick.DrawLine(xx, pow(10,uymin), xx, pow(10,uymin) + (i%100 == 0 ? 2*length : length));
else
tick.DrawLine(xx, uymin, xx, uymin + (i%100 == 0 ? 2*length : length));
}
// x-axis labels
//--------------------------------------------------------------------------
Float_t ylatex = (c1->GetLogy()) ? pow(10,uymin) - 1.3*length : uymin - 2*length;
for (Int_t i=xlow; i<=xup; i+=100) {
Float_t xx = i;
TLatex* latex = new TLatex(xx, ylatex, Form("%.0f", xx));
latex->SetTextAlign( 22);
latex->SetTextFont ( 42);
latex->SetTextSize (0.035);
latex->Draw("same");
}
}
// Draw the second canvas
//----------------------------------------------------------------------------
TCanvas* c2 = new TCanvas(“c2”, “c2”, 730, 50, 700, 500);
c2->SetLogx();
c2->SetLogy();
h2->GetXaxis()->SetMoreLogLabels();
h2->GetXaxis()->SetNoExponent();
h2->Draw();
gPad->Modified(); gPad->Update(); // make sure it’s drawn
// http://root.cern.ch/root/html/TF1.html#TF1:TF1@1
// http://root.cern.ch/root/html/TFormula.html#TFormula:Analyze
TF1 *f_h2_log10_x_axis = new TF1(“f_h2_log10_x_axis”, // name
"log10(x)", // formula
h2->GetXaxis()->GetXmin(), // xmin
h2->GetXaxis()->GetXmax()); // xmax
// http://root.cern.ch/root/html/TGaxis.html#TGaxis:TGaxis@3
// http://root.cern.ch/root/html/TGaxis.html#TGaxis:PaintAxis
TGaxis *a = new TGaxis(h2->GetXaxis()->GetXmin(), // xmin
h2->GetYaxis()->GetXmin(), // ymin
h2->GetXaxis()->GetXmax(), // xmax
h2->GetYaxis()->GetXmin(), // ymax
"f_h2_log10_x_axis", // funcname
100006, // ndiv (try 100006 or 506, don’t try 1006)
“BS”, // chopt (try “BS” or “UBS”)
0.0); // gridlength
// a->SetTickSize(h2->GetTickLength(“X”)); // use “the same” size
a->SetTickSize(1.5 * h2->GetTickLength(“X”)); // make it bigger
h2->SetTickLength(0.0, “X”); // get rid of “original” ticks
if (!(TString(a->GetOption())).Contains(“U”)) {
a->SetLabelFont(h2->GetLabelFont(“X”)); // use “the same” font
a->SetLabelSize(h2->GetLabelSize(“X”)); // use “the same” size
h2->SetLabelSize(0.0, “X”); // get rid of “original” labels
}
a->Draw();
gPad->Modified(); gPad->Update(); // make sure it’s redrawn
}[/code] Note: there is a bug (at least in ROOT 5.28, 5.32 and 5.34) somewhere in the procedure that manages the “number of 2nd divisions” for a TGaxis. One asks for 10 but one gets 9, so it’s better to avoid it (instead of 10 “2nd divisions”, one can use 10 “3rd divisions”, which work fine, but are “smaller” unfortunately).