How to change range of TGraph

Dear Rooters
At the time of drawing a graph, I want to set the range in both X-axis and Y-axis in my macro through command.
It is possible by clicking on the canvas and getting TAxis and then SetRange option.
But I want to set the range in my programme.
Please Give me suggestion.

With regards.
Tapasi

{
   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*");
}
2 Likes

Meanwhile I was able to do it.
Just one last unrelated thing:
Any idea on how to add an extra pad to an already divided canvas? Imagine I have two columns and want a third one. Iā€™m doing this by clearing the canvas and re-dividing it, but I feel like there should be a more elegant way of doing it.

Thanks!

You can create as many pad placed where you want using TPad, but
the already existing pads will not move automatically to make room for the extra pad(s)