# How to set range of X-axis in multigraph

**URL:** <https://root-forum.cern.ch/t/how-to-set-range-of-x-axis-in-multigraph/48907>\
**Category:** Newbie\
**Created:** [February 22, 2022, 3:25pm UTC](https://root-forum.cern.ch/t/how-to-set-range-of-x-axis-in-multigraph/48907 "2022-02-22T15:25:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anees\_Khan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/anees_khan/32/28677_2.png) [@Anees\_Khan](https://root-forum.cern.ch/u/Anees_Khan)\
**Post date:** [February 22, 2022, 3:25pm UTC](https://root-forum.cern.ch/t/how-to-set-range-of-x-axis-in-multigraph/48907/1 "2022-02-22T15:25:09Z")

</div>

![Screenshot from 2022-02-22 20-20-04](https://root-forum.cern.ch/uploads/default/original/3X/1/2/1296ad158d41f531eca198a2b504b15c3899fa6d.png)  
How to set range of X-axis as 0.114 0.116 0.118 0.12.  
Please need quick guide if possible.  
Thanks.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [February 22, 2022, 3:32pm UTC](https://root-forum.cern.ch/t/how-to-set-range-of-x-axis-in-multigraph/48907/2 "2022-02-22T15:32:24Z")

</div>

Can you post the macro producing this plot ? it will be easier to modify it directly.

---

<div class="post-metadata">

**Author:** ![Anees\_Khan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/anees_khan/32/28677_2.png) [@Anees\_Khan](https://root-forum.cern.ch/u/Anees_Khan)\
**Post date:** [February 22, 2022, 3:38pm UTC](https://root-forum.cern.ch/t/how-to-set-range-of-x-axis-in-multigraph/48907/3 "2022-02-22T15:38:45Z")

</div>

```auto
{

	TCanvas *c1 = new TCanvas("c1","c1",600,400);
	TGraphErrors *gr =new TGraphErrors();
        gr->SetTitle("Graph");
        gr-> GetXaxis()->SetTitle("alpha");
        gr-> GetYaxis()->SetTitle("Cross Section");
	double x , y , ex ,ey;
	int n = 0 ;
		n= gr->GetN();//take actual nbr of data file 
		gr->SetPoint(n,0.118001,10.07);//for defining the point
		gr->SetPointError(n ,0.001 ,1.53);
		gr->SetLineColor(2);
		gr->SetMarkerColor(6);
              gr->SetMarkerStyle(22);
	gr->Draw();
	 TGraphErrors *gr1 =new TGraphErrors();
        double x1 , y1 , ex1 ,ey1;
        int m = 0 ;
                m= gr1->GetN();//take actual nbr of data file 
                gr1->SetPoint(m,0.118001,10.07);//for defining the point
                gr1->SetPointError(n ,0.0 ,1.71);
		gr1->SetLineColor(2);
                gr1->SetMarkerColor(6);
              gr1->SetMarkerStyle(22);
       gr1->Draw();
	 TGraphErrors *gr2 =new TGraphErrors();
        double x12 , y12 , ex12 ,ey12;
        int p = 0 ;
                p= gr2->GetN();//take actual nbr of data file 
                gr2->SetPoint(p,0.118,10.58);//for defining the point
                gr2->SetPointError(n ,0.002 ,1.15);
		gr2->SetLineColor(3);
                gr2->SetMarkerColor(6);
              gr2->SetMarkerStyle(23);
        gr2->Draw();
TGraphErrors *gr3 =new TGraphErrors();
        double x122 , y122 , ex122 ,ey122;
        int q = 0 ;
                q= gr3->GetN();
                gr3->SetPoint(q,0.118,10.58);
                gr3->SetPointError(n ,0.0 ,1.34);
		gr3->SetLineColor(3);
                gr3->SetMarkerColor(6);
              gr3->SetMarkerStyle(23);
        gr3->Draw();
TMultiGraph *mg = new TMultiGraph();
   mg->Add(gr);
   mg->Add(gr1);
  mg->Add(gr2);
   mg->Add(gr3);
 mg-> GetXaxis()->SetTitle("alpha");
   mg-> GetYaxis()->SetTitle("Cross Section");
   gPad->Modified();
   mg->GetXaxis()->SetLimits(0,0.120);
      mg->SetMinimum(0.);
   mg->SetMaximum(15.);
  
   
   mg->Draw("ALP");
   
   auto *leg = new TLegend(0.2, 0.2, 0.5, 0.4);
   leg->SetHeader("Inner bars= as outer Bar=Pdf +as","P");
   leg->AddEntry(gr,"CT10","P");
   leg->AddEntry(gr2,"CT14","P");
   leg->Draw();

```

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [February 22, 2022, 3:45pm UTC](https://root-forum.cern.ch/t/how-to-set-range-of-x-axis-in-multigraph/48907/4 "2022-02-22T15:45:27Z")

</div>

```auto
{
   TCanvas *c1 = new TCanvas("c1","c1",600,400);
   TGraphErrors *gr =new TGraphErrors();
   gr->SetTitle("Graph");
   gr-> GetXaxis()->SetTitle("alpha");
   gr-> GetYaxis()->SetTitle("Cross Section");
   double x , y , ex ,ey;
   int n = 0 ;
   n= gr->GetN();//take actual nbr of data file
   gr->SetPoint(n,0.118001,10.07);//for defining the point
   gr->SetPointError(n ,0.001 ,1.53);
   gr->SetLineColor(2);
   gr->SetMarkerColor(6);
   gr->SetMarkerStyle(22);
   gr->Draw();
   TGraphErrors *gr1 =new TGraphErrors();
   double x1 , y1 , ex1 ,ey1;
   int m = 0 ;
   m= gr1->GetN();//take actual nbr of data file
   gr1->SetPoint(m,0.118001,10.07);//for defining the point
   gr1->SetPointError(n ,0.0 ,1.71);
   gr1->SetLineColor(2);
   gr1->SetMarkerColor(6);
   gr1->SetMarkerStyle(22);
   gr1->Draw();
   TGraphErrors *gr2 =new TGraphErrors();
   double x12 , y12 , ex12 ,ey12;
   int p = 0 ;
   p= gr2->GetN();//take actual nbr of data file
   gr2->SetPoint(p,0.118,10.58);//for defining the point
   gr2->SetPointError(n ,0.002 ,1.15);
   gr2->SetLineColor(3);
   gr2->SetMarkerColor(6);
   gr2->SetMarkerStyle(23);
   gr2->Draw();
   TGraphErrors *gr3 =new TGraphErrors();
   double x122 , y122 , ex122 ,ey122;
   int q = 0 ;
   q= gr3->GetN();
   gr3->SetPoint(q,0.118,10.58);
   gr3->SetPointError(n ,0.0 ,1.34);
   gr3->SetLineColor(3);
   gr3->SetMarkerColor(6);
   gr3->SetMarkerStyle(23);
   gr3->Draw();
   TMultiGraph *mg = new TMultiGraph();
   mg->Add(gr);
   mg->Add(gr1);
   mg->Add(gr2);
   mg->Add(gr3);
   mg-> GetXaxis()->SetTitle("alpha");
   mg-> GetYaxis()->SetTitle("Cross Section");
   gPad->Modified();
   mg->GetXaxis()->SetLimits(0,0.120);
   mg->SetMinimum(0.);
   mg->SetMaximum(15.);

   mg->Draw("ALP");
   gPad->Update();
   mg->GetXaxis()->SetNdivisions(508);

   auto *leg = new TLegend(0.2, 0.2, 0.5, 0.4);
   leg->SetHeader("Inner bars= as outer Bar=Pdf +as","P");
   leg->AddEntry(gr,"CT10","P");
   leg->AddEntry(gr2,"CT14","P");
   leg->Draw();
}

```

 ![Screenshot 2022-02-22 at 16.44.03](https://root-forum.cern.ch/uploads/default/original/3X/5/3/53bda7a5205193febabd50f9c5e1b483035e94c0.png)

---

<div class="post-metadata">

**Author:** ![Anees\_Khan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/anees_khan/32/28677_2.png) [@Anees\_Khan](https://root-forum.cern.ch/u/Anees_Khan)\
**Post date:** [February 22, 2022, 4:27pm UTC](https://root-forum.cern.ch/t/how-to-set-range-of-x-axis-in-multigraph/48907/5 "2022-02-22T16:27:29Z")

</div>

How to make a difference of 0.114-0.116

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [February 22, 2022, 6:03pm UTC](https://root-forum.cern.ch/t/how-to-set-range-of-x-axis-in-multigraph/48907/6 "2022-02-22T18:03:22Z")

</div>

```cpp
   mg->Draw("ALP");
   gPad->Update();
   mg->GetXaxis()->SetLimits(0.114, 0.120); // or, e.g., (0.1138, 0.1202)

```

---

<div class="post-metadata">

**Author:** ![Anees\_Khan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/anees_khan/32/28677_2.png) [@Anees\_Khan](https://root-forum.cern.ch/u/Anees_Khan)\
**Post date:** [February 22, 2022, 6:27pm UTC](https://root-forum.cern.ch/t/how-to-set-range-of-x-axis-in-multigraph/48907/7 "2022-02-22T18:27:51Z")

</div>

Thanks

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [February 23, 2022, 7:28am UTC](https://root-forum.cern.ch/t/how-to-set-range-of-x-axis-in-multigraph/48907/8 "2022-02-23T07:28:10Z")

</div>

Two small comments:

1. The upper limit at 0.12 is exactly the upper X value of the green error bars. Therefore it is hard to know if the error bar is clipped or not.
2. The choice of markers is not the best. See [ROOT: tutorials/graphics/markerwarning.C File Reference](https://root.cern/doc/master/markerwarning_8C.html)
