jkrane
August 5, 2016, 6:25pm
1
Hello Rooters,
I’m using ROOT 5.34/34 in Windows. I’d like to make a plot with Years on the bottom x-axis, restated as Days on the top x-axis. I can’t seem to get this to work, yet nobody seems to have reported a bug. It must be me! But I can’t find my mistake. Please help…
My code:
TH2D *h=new TH2D("h","TGaxis Demo; Years; ",10,0.,0.3,10,0.,1.);
TF1 *f=new TF1("f","365.0*x",0.,0.3);
TGaxis *g=new TGaxis(0.,1.,0.3,1.,"f",510,"-");
g->SetTitle("Days");
h->Draw();
g->Draw();
…yields the attached graph. The axis, which should run from 0 to 110 days or so, instead runs from 0 to 0.3, just like the Years axis. I’m confused.
- John
jkrane
August 8, 2016, 7:01pm
2
Does anybody have a working example of TGaxis with function?
- John
Hi,
what about this:
{
TCanvas *c = new TCanvas();
TH2D *h=new TH2D("h","TGaxis Demo; Years; ",10,0.,0.3,10,0.,1.);
TF1 *f=new TF1("f","365.0*x",0.,0.3);
TGaxis *g=new TGaxis(0.,1.,0.3, 1, 0, 365*0.3,510,"-");
g->SetTitle("Days");
h->Draw();
g->Draw();
}
]
Btw has nothing to with your function, purely graphics
Cheers
Otto
here the more general case:
Notice the upper limit: 0.3*365
Otto
{
TCanvas *c = new TCanvas();
TH2D *h=new TH2D("h","TGaxis Demo; Years; ",10,0.,0.3,10,0.,1.);
TF1 *f=new TF1("f","x*365",0.,0.3*365.);
TGaxis *g=new TGaxis(0.,1.,0.3, 1,"f",510,"-");
//TGaxis *g=new TGaxis(0.,1.,0.3, 1, 0, 365*0.3,510,"-");
g->SetTitle("Days");
h->Draw();
g->Draw();
}