# How to draw a graph of crossection with uncertainies showing by color

**URL:** <https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820>\
**Category:** Newbie\
**Tags:** root\
**Created:** [February 16, 2022, 4:23pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820 "2022-02-16T16:23:10Z")\
**Posts on this page:** 20\
**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 16, 2022, 4:23pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820/1 "2022-02-16T16:23:10Z")

</div>

How to draw a line at some specific value of cross-section at x-axis having a color region showing uncertainties ?  
I am new so i can’t be able to add picture of graph.if anyone know please help me.  
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 16, 2022, 4:26pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820/2 "2022-02-16T16:26:54Z")

</div>

The simplest way to draw is line is to use [TLine](https://root.cern/doc/master/classTLine.html).

---

<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 16, 2022, 4:36pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820/3 "2022-02-16T16:36:03Z")

</div>

do you have a code or can you please guide me how to use TLine

---

<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 17, 2022, 7:44am UTC](https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820/4 "2022-02-17T07:44:38Z")

</div>

```auto
{
   Double_t x[5] = {10,20,30,40,50};
   Double_t y[5] = {2,3,5,7,8};
   auto *g = new TGraph(5,x,y);
   g->Draw("AL");
   gPad->Update();
   auto l = new TLine(30,gPad->GetUymin(),30,gPad->GetUymax());
   l->SetLineColor(kRed);
   l->SetLineWidth(5);
   l->Draw();
}

```

 ![Screenshot 2022-02-17 at 08.44.20](https://root-forum.cern.ch/uploads/default/original/3X/c/7/c76298dcaa79a169c717abcacbe57f7b08ef8dda.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 17, 2022, 1:22pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820/5 "2022-02-17T13:22:44Z")

</div>

thanks  
can i make line only without this graph and also can color differenly in the area between lets say inbetween 27 and 30.

---

<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 17, 2022, 1:27pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820/6 "2022-02-17T13:27:23Z")

</div>

![graph](https://root-forum.cern.ch/uploads/default/original/3X/7/7/77d910b754d191829f6bca2981dc81f60dd58676.png)  
How to make these type of graphs?

---

<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 17, 2022, 1:59pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820/7 "2022-02-17T13:59:24Z")

</div>

```auto
{
   auto c = new TCanvas();
   c->DrawFrame(10., 3., 50., 10);

   gPad->Update();
   auto b1 = new TBox(25,gPad->GetUymin(),35,gPad->GetUymax());
   b1->SetFillColor(kGreen);
   b1->SetFillStyle(1001);
   b1->Draw();

   auto b2 = new TBox(27,gPad->GetUymin(),33,gPad->GetUymax());
   b2->SetFillColor(kYellow);
   b2->SetFillStyle(1001);
   b2->Draw();

   auto l = new TLine(30,gPad->GetUymin(),30,gPad->GetUymax());
   l->SetLineColor(kRed);
   l->SetLineWidth(5);
   l->Draw();

   c->RedrawAxis();
}

```

 ![Screenshot 2022-02-17 at 14.58.54](https://root-forum.cern.ch/uploads/default/original/3X/e/0/e0e361d85c6b0bae82cf35c57db8d4943ebbf42d.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 17, 2022, 2:12pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820/8 "2022-02-17T14:12:59Z")

</div>

should i use error graph for cross-sections as shown?

---

<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 17, 2022, 2:43pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820/9 "2022-02-17T14:43:11Z")

</div>

Yes, for instance.  
Then you simply draw them just before `RedrawAxis`

---

<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 17, 2022, 3:28pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820/10 "2022-02-17T15:28:46Z")

</div>

Please also tell me how to draw these legends for color and line.  
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 17, 2022, 4:16pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820/11 "2022-02-17T16:16:23Z")

</div>

```auto
{
   auto c = new TCanvas();
   c->DrawFrame(-10., 3., 50., 10);

   gPad->Update();
   auto b1 = new TBox(25,gPad->GetUymin(),35,gPad->GetUymax());
   b1->SetFillColor(kGreen);
   b1->SetFillStyle(1001);
   b1->Draw();

   auto b2 = new TBox(27,gPad->GetUymin(),33,gPad->GetUymax());
   b2->SetFillColor(kYellow);
   b2->SetFillStyle(1001);
   b2->Draw();

   auto l = new TLine(30,gPad->GetUymin(),30,gPad->GetUymax());
   l->SetLineColor(kRed);
   l->SetLineWidth(5);
   l->Draw();

   auto *leg = new TLegend(0.2, 0.2, 0.5, 0.4);
   leg->AddEntry(b1,"Legend 1","F");
   leg->AddEntry(b2,"Legend 2","F");
   leg->Draw();
   c->RedrawAxis();
}

```

 ![Screenshot 2022-02-17 at 17.15.48](https://root-forum.cern.ch/uploads/default/original/3X/b/6/b62b132678d35dc341e224d5a665634e7a9e62c2.png)

---

<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 17, 2022, 4:17pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820/12 "2022-02-17T16:17:22Z")

</div>

May be ask your colleagues to provide you this macro ? it will be simpler.

---

<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 19, 2022, 10:02am UTC](https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820/14 "2022-02-19T10:02:59Z")

</div>

![Screenshot from 2022-02-19 15-00-06](https://root-forum.cern.ch/uploads/default/original/3X/4/3/43fd51eb9fa783b3a14bfafdd4f86e11a3dabd5e.png)  
how to show lines on the color region that are hide behind color?

---

<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 20, 2022, 3:14pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820/15 "2022-02-20T15:14:34Z")

</div>

waiting for any suggestions please

---

<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 20, 2022, 4:04pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820/16 "2022-02-20T16:04:56Z")

</div>

In the end, try to add: `your_graph->Draw("P");`

---

<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 20, 2022, 4:21pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820/17 "2022-02-20T16:21:20Z")

</div>

not working

---

<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 20, 2022, 4:22pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820/18 "2022-02-20T16:22:47Z")

</div>

Attach your macro which creates your plot.

---

<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 20, 2022, 4:25pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820/19 "2022-02-20T16:25:03Z")

</div>

{

```
      TCanvas *c1 = new TCanvas("c1","Examples of TGaxis",10,10,700,500);

```

c1-\>Range(-10,-1,10,1);

```
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(0,14.23,3);//for defining the point
	gr->SetPointError(0 ,2.5 ,0);
	gr->SetLineColor(3);
	gr->SetMarkerColor(8);
          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(0,14.99,4);//for defining the point
            gr1->SetPointError(0 ,5.08 ,0);
	gr1->SetLineColor(2);
            gr1->SetMarkerColor(7);
          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(0,14.49,7);//for defining the point
            gr2->SetPointError(0 ,5.440 ,0);
	gr2->SetLineColor(2);
            gr2->SetMarkerColor(6);
          gr2->SetMarkerStyle(22);
    gr2->Draw();

```

TGraphErrors \*gr3 =new TGraphErrors();  
double x122 , y122 , ex122 ,ey122;  
int q = 0 ;  
q= gr3-\>GetN();  
gr3-\>SetPoint(0,12.98,8);  
gr3-\>SetPointError(0 ,0.663 ,0);  
gr3-\>SetLineColor(2);  
gr3-\>SetMarkerColor(5);  
gr3-\>SetMarkerStyle(22);  
gr3-\>Draw();  
//////////////////////////////////////

```
TMultiGraph *mg = new TMultiGraph();

```

mg-\>Add(gr);  
mg-\>Add(gr1);  
mg-\>Add(gr2);  
mg-\>Add(gr3);

mg-\> GetXaxis()-\>SetTitle(“Cross Section”);  
mg-\>Draw(“P SAME”);  
auto b1 = new TBox(9.7953,2.75,12.0046,8.2);  
b1-\>SetFillColor(kGreen);  
b1-\>SetFillStyle(1001);  
b1-\>Draw();

auto l = new TLine(10.9,2.75,10.9,8.2);  
l-\>SetLineColor(kRed);  
l-\>SetLineWidth(5);  
l-\>Draw();

---

<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 20, 2022, 4:28pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820/20 "2022-02-20T16:28:08Z")

</div>

Move the `mg->Draw("P");` to the end of your macro.

---

<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 20, 2022, 4:30pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820/21 "2022-02-20T16:30:18Z")

</div>

![Screenshot from 2022-02-20 21-29-23](https://root-forum.cern.ch/uploads/default/original/3X/e/d/ed92dab12a12326e96133908da7064f1c625901c.png)  
now no color box appear

[Next page](https://root-forum.cern.ch/t/how-to-draw-a-graph-of-crossection-with-uncertainies-showing-by-color/48820.md?page=2)
