Adding a second x axis to a TGraph in the CERN ROOT program

Xavier Hubbard Anderson picture Xavier Hubbard Anderson · Jul 3, 2012 · Viewed 8.8k times · Source

does anyone know the method or code to add a second x axis to a TGraph in CERN's ROOT program? Ive been searching the root website and its documentation almost always confuses me. What i need is just one plot of data, but a second X axis on top whose values are a function of the bottom x axis' values. Its basically so lazy people dont have to convert from the numbers of the bottom x axis to the top x axis.

For a simple example (if i wasnt clear)

Say you have a sine curve which is some function of theta. On the top x axis we could have degrees whereas on the bottom we could have radians with 360deg corresponding to 2pi rad...

Any help would be appreciated!

Answer

Ryan picture Ryan · Jul 31, 2013

TGaxis is the class you are looking for to draw extra axes wherever you desire. Grabbing the world coordinate for your pad you can then superimpose like so. Replace low and high with the appropriate limits.

// your graph code here...
TGraph->Draw("AP");    

TGaxis *axis = new TGaxis(gPad->GetUxmin(),gPad->GetUymax(),gPad->GetUxmax(),gPad->GetUymax(),low,high,510,"+L");
axis->Draw();

Check out TGaxis documentation for more examples.