# Problem with logarithmic X/Y axes with TNtuple

**URL:** <https://root-forum.cern.ch/t/problem-with-logarithmic-x-y-axes-with-tntuple/14497>\
**Category:** ROOT\
**Created:** [June 28, 2012, 6:02pm UTC](https://root-forum.cern.ch/t/problem-with-logarithmic-x-y-axes-with-tntuple/14497 "2012-06-28T18:02:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdst](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/919ad9/32.png) [@jdst](https://root-forum.cern.ch/u/jdst)\
**Post date:** [June 28, 2012, 6:02pm UTC](https://root-forum.cern.ch/t/problem-with-logarithmic-x-y-axes-with-tntuple/14497/1 "2012-06-28T18:02:34Z")

</div>

Hi,

As a simple example some times ago, i’m trying to plot 3 sets of data using TNtuple with a logarithmic axis, either x or y.  
The problem is that with “SetLogx(1)” or “SetLogy(1)”, i can’t see all points since i can’t fix the log scale myself, and i don’t see a solution actually.

Below one simple example :

```auto
#include <TStyle.h>
#include <TCanvas.h>
#include <TNtuple.h>
{
TNtuple* nt = new TNtuple("nt","","a:b:c");
TCanvas *Can = new TCanvas("Can","",200,10,600,400);

Double_t x[16] = {1.00, 2.00, 6.00, 7.00, 3.00, 10.00, 0.20, 5.55,
      20.50, 9.75, 1.50, 8.00, 5.00, 0.95, 3.85, 8.70};
Double_t y[16] = {1.00, 2.00, 6.00, 7.00, 3.00, 10.00, 0.20, 5.55,
      20.50, 9.75, 1.50, 8.00, 5.00, 0.95, 3.85, 8.70};
Double_t z[16] = {0.001, 2.50, 600.00, 0.00001, 30.00, 10.001, 0.00020, 500000.55,
      20.50, 9.75, 280000.50, 8.00, 5.00, 0.95, 3.85, 8.70};

Double_t x3, y3, z3;

for(Int_t h1 =0;h1<16;++h1)
{
x3 = x[h1];
y3 = y[h1];
z3 = z[h1]; nt->Fill(x3,y3,z3);
}
gPad->SetLogy(1);
Can->SetTickx(1);
gStyle->SetOptStat(0);
gStyle->SetPalette(1,0);
nt->SetMarkerStyle(20);
nt->SetMarkerSize(1);
nt->Draw("b:a:c","c","colz");
}
```

In log scale, i can’t see points xith x\<1 here.

Any suggestions ?

Thanks

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 29, 2012, 7:25am UTC](https://root-forum.cern.ch/t/problem-with-logarithmic-x-y-axes-with-tntuple/14497/2 "2012-06-29T07:25:36Z")

</div>

May be something like that would help:

```auto
{
TNtuple* nt = new TNtuple("nt","","a:b:c");
TCanvas *Can = new TCanvas("Can","Can",200,10,600,400);

Double_t x[16] = {1.00, 2.00, 6.00, 7.00, 3.00, 10.00, 0.20, 5.55,
      20.50, 9.75, 1.50, 8.00, 5.00, 0.95, 3.85, 8.70};
Double_t y[16] = {1.00, 2.00, 6.00, 7.00, 3.00, 10.00, 0.20, 5.55,
      20.50, 9.75, 1.50, 8.00, 5.00, 0.95, 3.85, 8.70};
Double_t z[16] = {0.001, 2.50, 600.00, 0.00001, 30.00, 10.001, 0.00020, 500000.55,
      20.50, 9.75, 280000.50, 8.00, 5.00, 0.95, 3.85, 8.70};

Double_t x3, y3, z3;

for(Int_t h1 =0;h1<16;++h1)
{
x3 = x[h1];
y3 = y[h1];
z3 = z[h1]; nt->Fill(x3,y3,z3);
}
Can->SetTickx(1);
gStyle->SetOptStat(0);
gStyle->SetPalette(1,0);
nt->SetMarkerStyle(20);
nt->SetMarkerSize(1);
nt->Draw("b:a:c>>h(100,0.01,22,100,0.01,22)","","col ");
gPad->SetLogx(1);

}

```

---

<div class="post-metadata">

**Author:** ![jdst](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/919ad9/32.png) [@jdst](https://root-forum.cern.ch/u/jdst)\
**Post date:** [June 29, 2012, 10:22am UTC](https://root-forum.cern.ch/t/problem-with-logarithmic-x-y-axes-with-tntuple/14497/3 "2012-06-29T10:22:20Z")

</div>

thanks, but i don’t really understand the use of “nt-\>Draw(“b:a:c\>\>h(100,0.01,22,100,0.01,22)”,”","col “);” :

Actually i understand that the fourth “h” command, here 100, is xmax - xmin (i tried others values to get it), but i don’t understand the others, especially if i want to use log scale on y axis.

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [June 29, 2012, 11:28am UTC](https://root-forum.cern.ch/t/problem-with-logarithmic-x-y-axes-with-tntuple/14497/4 "2012-06-29T11:28:56Z")

</div>

Search for “\>\>” in [http://root.cern.ch/download/doc/ROOTUsersGuideHTML/ch12s20.html#d5e17157](http://root.cern.ch/download/doc/ROOTUsersGuideHTML/ch12s20.html#d5e17157) and in [http://root.cern.ch/root/html/TTree.html#TTree:Draw@2](http://root.cern.ch/root/html/TTree.html#TTree:Draw@2)

---

<div class="post-metadata">

**Author:** ![jdst](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/919ad9/32.png) [@jdst](https://root-forum.cern.ch/u/jdst)\
**Post date:** [June 29, 2012, 1:23pm UTC](https://root-forum.cern.ch/t/problem-with-logarithmic-x-y-axes-with-tntuple/14497/5 "2012-06-29T13:23:10Z")

</div>

OK i see now, but the problem with this code

```auto
nt->Draw("b:a:c>>h(100,0.01,22,100,0.01,22)","","col ");
```

is that it just fix x and color axes, but not y axis (“b”).  
To be able to have logarithmic y axis, i tried for instance

```auto
nt->Draw("b:a:c>>h(10,0.01,1,100,0.01,22,100,0.01,22)","","colz");
```

but the result is completely wrong : is there a possibility to improve this function ?

Thanks

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [July 2, 2012, 9:56am UTC](https://root-forum.cern.ch/t/problem-with-logarithmic-x-y-axes-with-tntuple/14497/6 "2012-07-02T09:56:13Z")

</div>

In order to get “logarithmic y axis”, simply add “gPad-\>SetLogy(1);” in the end of Olivier’s example (right after “gPad-\>SetLogx(1);”).

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [July 2, 2012, 12:43pm UTC](https://root-forum.cern.ch/t/problem-with-logarithmic-x-y-axes-with-tntuple/14497/7 "2012-07-02T12:43:49Z")

</div>

Try this: [code]{  
TNtuple\* nt = new TNtuple(“nt”,"",“a:b:c”);  
TCanvas \*Can = new TCanvas(“Can”,“Can”,200,10,600,400);

Double\_t x[16] = {1.00, 2.00, 6.00, 7.00, 3.00, 10.00, 0.20, 5.55,  
20.50, 9.75, 1.50, 8.00, 5.00, 0.95, 3.85, 8.70};  
Double\_t y[16] = {1.00, 2.00, 6.00, 7.00, 3.00, 10.00, 0.20, 5.55,  
20.50, 9.75, 1.50, 8.00, 5.00, 0.95, 3.85, 8.70};  
Double\_t z[16] = {0.001, 2.50, 600.00, 0.00001, 30.00, 10.001, 300000.0, 500000.55,  
20.50, 9.75, 280000.50, 8.00, 5.00, 0.95, 3.85, 8.70};

Double\_t x3, y3, z3;

for(Int\_t h1 =0;h1\<16;++h1)  
{  
x3 = x[h1];  
y3 = y[h1];  
z3 = z[h1]; nt-\>Fill(x3,y3,z3);  
}  
Can-\>SetTickx(1);  
gStyle-\>SetOptStat(0);  
gStyle-\>SetPalette(1,0);  
nt-\>SetMarkerStyle(20);  
nt-\>SetMarkerSize(1);

#if 0 /\* 0 or 1 _/  
Double\_t xmin = 0.01, xmax = 50, ymin = 0.01, ymax = 50;  
 #else /_ 0 or 1 \*/  
nt-\>SetEstimate(nt-\>GetEntries() + 1);  
Double\_t xmin = nt-\>GetMinimum(“a”); // “a” is X in the nt-\>Draw below  
Double\_t xmax = nt-\>GetMaximum(“a”);  
Double\_t ymin = nt-\>GetMinimum(“b”); // “b” is Y in the nt-\>Draw below  
Double\_t ymax = nt-\>GetMaximum(“b”);  
xmin \*= ((xmin \< 0.0) ? 1.000001 : 0.999999);  
xmax \*= ((xmax \< 0.0) ? 0.999999 : 1.000001);  
ymin \*= ((ymin \< 0.0) ? 1.000001 : 0.999999);  
ymax _= ((ymax \< 0.0) ? 0.999999 : 1.000001);  
 #endif /_ 0 or 1 \*/

// [http://root.cern.ch/root/html/TTree.html#TTree:Draw@2](http://root.cern.ch/root/html/TTree.html#TTree:Draw@2)  
#if 1 /\* 0 or 1 \*/  
TH2F _h = new TH2F(“h”, “h”, 100, xmin, xmax, 100, ymin, ymax);  
nt-\>Draw(“b:a:c\>\>h”, “”, “colz”); // warning: TTree::Draw destroys “h”  
// gPad-\>Modified(); gPad-\>Update();  
h-\>GetXaxis()-\>SetLimits(xmin, xmax); // restore proper “h” X axis limits  
h-\>GetYaxis()-\>SetLimits(ymin, ymax); // restore proper “h” Y axis limits  
 #else /_ 0 or 1 \*/  
nt-\>Draw(“b:a:c”, “”, “colz”); // note: TTree::Draw creates a “htemp”  
// gPad-\>Modified(); gPad-\>Update();  
// TH2F \*htemp = ((TH2F _)(gPad-\>GetPrimitive(“htemp”)));  
htemp-\>GetXaxis()-\>SetLimits(xmin, xmax); // set proper “htemp” X axis limits  
htemp-\>GetYaxis()-\>SetLimits(ymin, ymax); // set proper “htemp” Y axis limits  
 #endif /_ 0 or 1 \*/

gPad-\>SetLogx(1);  
gPad-\>SetLogy(1);  
// gPad-\>Modified(); gPad-\>Update();  
}[/code] Note: the TTree::Draw method unconditionally deletes the “original” histogram “h”, regardless whether one says “b:a:c\>\>h” or “b:a:c\>\>+h”. The X and Y “numbers of bins” of the histogram will be set to 20 (instead of the original 100). What’s more important, it also changes the X and the Y axes limits of the histogram (it calculates them automatically, without any respect for the “original” settings). As a result, in case one uses logarithmic axes, NOT ALL POINTS ARE DRAWN (and one gets NO WARNING that parts of ones histogram are removed from the picture). Once one “manually” restores proper X and Y axes limits, one should see all points (unless there are “additional” points outside of these limits, of course).

---

<div class="post-metadata">

**Author:** ![jdst](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/919ad9/32.png) [@jdst](https://root-forum.cern.ch/u/jdst)\
**Post date:** [July 3, 2012, 8:23am UTC](https://root-forum.cern.ch/t/problem-with-logarithmic-x-y-axes-with-tntuple/14497/8 "2012-07-03T08:23:59Z")

</div>

Thanks ! It works very well !
