Graph with 2 x axis

Hi,

I am facing an unpleasant difficulty when I trie to plot some data with two different range on the x axis. I can not get the ticks of the up axis out of the down axis. I will appreciate some help.

[code]
void dispersion(){

gStyle->SetPadTickX(0);
gStyle->SetPadTickY(0);

TFile* file = new TFile(“sh.root”,“read”);
TNtuple* ntuple = (TNtuple*) file->Get(“ntuple”);
TCanvas* canvas = new TCanvas(“canvas”,“Dispersion”,700,500);

TPad *pad = new TPad(“pad”,"",0,0,1,1);
pad->Draw();
pad->cd();

TH1F *hr = pad->DrawFrame(0.74,1.74,0.9,1.95);
pad->GetFrame()->SetFillColor(0);

ntuple->Draw(“fun:lam”,"",“goff”);
TGraph* gFun = new TGraph(ntuple->GetSelectedRows(),ntuple->GetV2(),ntuple->GetV1());

ntuple->Draw(“pri:lam”,"",“goff”);
TGraph* gPri = new TGraph(ntuple->GetSelectedRows(),ntuple->GetV2(),ntuple->GetV1());

ntuple->Draw(“seg:lam”,"",“goff”);
TGraph* gSeg = new TGraph(ntuple->GetSelectedRows(),ntuple->GetV2(),ntuple->GetV1());

ntuple->Draw(“ter:lam”,"",“goff”);
TGraph* gTer = new TGraph(ntuple->GetSelectedRows(),ntuple->GetV2(),ntuple->GetV1());

ntuple->Draw(“qua:lam”,"",“goff”);
TGraph* gQua = new TGraph(ntuple->GetSelectedRows(),ntuple->GetV2(),ntuple->GetV1());

ntuple->Draw(“qui:lam”,"",“goff”);
TGraph* gQui = new TGraph(ntuple->GetSelectedRows(),ntuple->GetV2(),ntuple->GetV1());

ntuple->Draw(“sex:lam”,"",“goff”);
TGraph* gSex = new TGraph(ntuple->GetSelectedRows(),ntuple->GetV2(),ntuple->GetV1());

ntuple->Draw(“set:lam”,"",“goff”);
TGraph* gSet = new TGraph(ntuple->GetSelectedRows(),ntuple->GetV2(),ntuple->GetV1());

TMultiGraph *mg = new TMultiGraph();

mg->Add(gFun);
mg->Add(gPri);
mg->Add(gSeg);
mg->Add(gTer);
mg->Add(gQua);
mg->Add(gQui);
mg->Add(gSex);

mg->Draw(“same l”);

canvas->cd();

TPad *overlay = new TPad(“overlay”,"",0,0,1,1);
overlay->SetFillStyle(4000);
overlay->SetFillColor(0);
overlay->SetFrameFillStyle(4000);
overlay->Draw();
overlay->SetTicks(0,0);
overlay->cd();
Double_t xmin = 1.5e-6;
Double_t ymin = pad->GetUymin();
Double_t xmax = 1.59e-6;
Double_t ymax = pad->GetUymax();
TH1F *hframe = overlay->DrawFrame(xmin,ymin,xmax,ymax);
hframe->GetXaxis()->SetLabelOffset(99);
hframe->GetYaxis()->SetLabelOffset(99);
hframe->GetYaxis()->SetTickLength(0);

ntuple->Draw(“funp:lamp”,"",“goff”);
TGraph* gPum = new TGraph(ntuple->GetSelectedRows(),ntuple->GetV2(),ntuple->GetV1());
gPum->SetLineColor(2);
gPum->Draw(“same l”);

TGaxis *axis = new TGaxis(xmin,ymax,xmax,ymax,xmin,xmax,510,“L-”);
axis->SetLineColor(kRed);
axis->SetLabelColor(kRed);
axis->SetTitleOffset(0);
axis->Draw();
axis->SetTickLength(0);
}[/code]

Renato.

I guess that’s this part of code you are talking about:

TGaxis *axis = new TGaxis(xmin,ymax,xmax,ymax,xmin,xmax,510,"L-");
axis->SetLineColor(kRed);
axis->SetLabelColor(kRed);
axis->SetTitleOffset(0);
axis->Draw();
axis->SetTickLength(0);

?

I think the problem is there, but I am not so sure. For a while I was thinking that it could be in the TFrame or in the option that I chose to draw the graphics.

Renato.

would be good to have a small macro I can run to see the problem.

OK

[code]void teste(){

TCanvas* canvas = new TCanvas(“canvas”,“teste”,700,500);

TPad *pad = new TPad(“pad”,"",0,0,1,1);
pad->Draw();
pad->cd();

TH1F *hr = pad->DrawFrame(0.74,1.74,0.9,1.95);
pad->GetFrame()->SetFillColor(0);

Int_t i = 6;

Double_t lamp[] = {1.5,1.52,1.54,1.56,1.58,1.60};
Double_t lam[] = {0.7,0.72,0.74,0.75,0.77,0.8};
Double_t n1[] = {1.85,1.84,1.83,1.82,1.81,1.80};
Double_t n2[] = {1.82,1.81,1.80,1.79,1.78,1.77};
Double_t np[] = {1.828,1.824,1.821,1.817,1.814,1.810};

TGraph* gr1 = new TGraph(i,lam,n1);
TGraph* gr2 = new TGraph(i,lam,n2);

TMultiGraph *mg = new TMultiGraph();

mg->Add(gr1);
mg->Add(gr2);

mg->Draw(“same l”);

canvas->cd();

TPad *overlay = new TPad(“overlay”,"",0,0,1,1);
overlay->SetFillStyle(4000);
overlay->SetFillColor(0);
overlay->SetFrameFillStyle(4000);
overlay->Draw();
overlay->SetTicks(0,0);
overlay->cd();
Double_t xmin = 1.5;
Double_t ymin = pad->GetUymin();
Double_t xmax = 1.59;
Double_t ymax = pad->GetUymax();
TH1F *hframe = overlay->DrawFrame(xmin,ymin,xmax,ymax);
hframe->GetXaxis()->SetLabelOffset(99);
hframe->GetYaxis()->SetLabelOffset(99);
hframe->GetYaxis()->SetTickLength(0);

gr3 = new TGraph(i,lamp,np);
gr3->SetLineColor(2);
gr3->Draw(“same l”);

TGaxis *axis = new TGaxis(xmin,ymax,xmax,ymax,xmin,xmax,510,“L-”);
axis->SetLineColor(kRed);
axis->SetLabelColor(kRed);
axis->SetTitleOffset(0);
axis->Draw();

}
[/code]

Renato

You said:

I get the attached picture with you macro.
Looking at it I am not sure to see whats wrong with the red axis.
Can you tell me what I should change ?


See the “down” X-axis (note the “double ticks” problem).

Yes I saw that… but as the top axis was mentioned I thought it was related to it. I will fix this double ticks

Well, one set of ticks on the “down” X-axis seems to be related to the “up” X-axis -> I think that’s the problem he’s talking about.

Just add:

      hframe->GetXaxis()->SetTickLength(0);

after:

   hframe->GetYaxis()->SetTickLength(0);