Y+ option of TGraph::Draw()

I’d like to overlay a graph on another graph with second Y axis
drawn on the right side using “Y+” option of TGraph::Draw().
To use the “Y+” option, the range of the x-axis of the second graph
must be same as the first one, or the display messes up.
But it seems to be impossible to expand the x-range of one graph
to adjust it to that of the other graph.
Is there any way to superimpose two graphs with seprate Y axises and a
common x axis in case like the attached example?

Thank you.
test.C (1.64 KB)

Replace the last 3 lines of your macro by:

  TGraph *g2 = new TGraph(10, x2, y2);
  g2->Draw("ALY+");
  g2->GetXaxis()->SetLabelSize(0); 

Hi, thank you for your reply.

g2->GetXaxis()->SetLabelSize(0) hides the labels of the second x axis, but tick marks still remain.
Even though you hide the tick marks too, I suspect that the second x axis is only “hidden” and the second graph has not been correctly overlayed – that is, the second graph is not plotted using the first x axis.

see class TMultiGraph and $ROOTSYS/tutorials/graphs/multigraph.C

Rene

Just in case you need it, here is an example macro showing how to define Tgraph ranges:

{
   Int_t n=20;
   Double_t x[n],y[n];
   for (Int_t i=0; i < n; i++) {
      x[i]=i*0.1;
      y[i]=10*sin(x[i]+0.2);
   }
   TGraph *gr1 = new TGraph (n,x,y);
   TAxis *axis = gr1->GetXaxis();

   axis->SetLimits(0.,5.);                 // along X
   gr1->GetHistogram()->SetMaximum(20.);   // along          
   gr1->GetHistogram()->SetMinimum(-20.);  //   Y     

   gr1->Draw("AC*");
}

[quote=“brun”]see class TMultiGraph and $ROOTSYS/tutorials/graphs/multigraph.C
[/quote]

Hi, thank you for your reply.

TMultigraph properly superimposes two graphs, but unfortunately drawing option cannot be specified separately.

[quote]TMultigraph properly superimposes two graphs, but unfortunately drawing option cannot be specified separately.
[/quote]
Yes, it can in teh Add function

mg.Add(gr,"lp");
Rene

[quote=“couet”]Just in case you need it, here is an example macro showing how to define Tgraph ranges:
[/quote]

TAxis::SetLimits is what I wanted.
Thank you very much!

[quote=“brun”]
Yes, it can in teh Add function

mg.Add(gr,"lp");
Rene[/quote]

I didn’t know that there is the second argument.
Thanks a lot.