# Help with TGaxis

I have two histograms. I plotted one histogram and using TGaxis I added one new x axis on the top of the pad. My second histogram is for that new axis. How do I plot second histogram on the same pad. More specifically, My first histogram has x axis from -10 to 10 and my second histogram has x axis from 0 to 100.When I plot second histogram it is shown up to 10 not up to 100.Y axis in both is just counts. In one sense -10 of first histogram corresponds to 0 for second histogram.
This is the process I used

``````TCanvas *c= new TCanvas();
r1->Draw();//r1 is my first histogram from -10 to 10
TF1 *f1 = new TF1("f1","x",0,100);
TGaxis *A = new TGaxis(-10,25,10,25,"f1",10,"+",5);
A->Draw();
r2->Draw("hist same");//r2 is my second histogram
``````

Any Help will be appreciated.
Thank You
KB

Hello,

Could you post your full macro so that we can try to reproduce what youâ€™re getting?

Cheers,
Jakbo

Hi Jakbo,
Here is the code.test.C (927 Bytes)

Thank You
KBUnderAllNW_VWBar18_VWPosAndTDCHistogramWithWithoutNWForGatingof12.root (10.4 KB)

Thank you! I see the problem now, actually Iâ€™m not sure if you can easily combine two x axis in the same plot. For two y axis, there is a tutorial.

@couet Are the different x axis possible?

Try (you will need to â€śconvertâ€ť it to use histograms instead of graphs):

BTW. Maybe you simply want:

``````{
TCanvas *c = new TCanvas("c", "c");
c->DrawFrame(-10, 0., 100., 25., "My Title;My X;My Y"); // draw the frame
TF1 *f1 = new TF1("f1", "x", 0., 100.);
f1->Draw("SAME"); // draw the function
r1->Draw("HIST SAME"); // r1 is my first histogram from -10 to 10
r2->Draw("HIST SAME"); // r2 is my second histogram
}
``````
1 Like

Thank You all for your help

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