# Error rectangles filled incorectly

**URL:** <https://root-forum.cern.ch/t/error-rectangles-filled-incorectly/35070>\
**Category:** Newbie\
**Created:** [July 9, 2019, 9:30am UTC](https://root-forum.cern.ch/t/error-rectangles-filled-incorectly/35070 "2019-07-09T09:30:52Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/marta/32/18269_2.png) [@Marta](https://root-forum.cern.ch/u/Marta)\
**Post date:** [July 9, 2019, 9:30am UTC](https://root-forum.cern.ch/t/error-rectangles-filled-incorectly/35070/1 "2019-07-09T09:30:52Z")

</div>

Hello,  
I have a problem with errors in my histogram - I would like to have error rectangles. For that, I need to set filling color to my histogram, as I found somewhere. So I do it, but then when I draw it, it fills not only the error rectangles, but also whole area under the graph. Error bars look just fine when I draw them, but I would like to have the rectangles.  
Any ideas how I could settle that? It is probably just something very simple, but I cannot find anything on this topic anywhere.  
Thank you very much!

---

<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:** [July 9, 2019, 9:33am UTC](https://root-forum.cern.ch/t/error-rectangles-filled-incorectly/35070/2 "2019-07-09T09:33:11Z")

</div>

Can you post a small piece of code reproducing the problem you encountered ?

---

<div class="post-metadata">

**Author:** ![Marta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/marta/32/18269_2.png) [@Marta](https://root-forum.cern.ch/u/Marta)\
**Post date:** [July 9, 2019, 9:38am UTC](https://root-forum.cern.ch/t/error-rectangles-filled-incorectly/35070/3 "2019-07-09T09:38:40Z")

</div>

Sure. Here it is:

```auto
void errorproblem(){
  TFile *tau = TFile::Open("data_out.root"); //just taking the histogram out of file
  TH1D *h = (TH1D*)tau->Get("h");
  h->SetFillColor(kGray); //setting filling color
 
  TCanvas *C = new TCanvas("C", "h", 1000, 800); 
  h->Draw("same hist E2");
}

```

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [July 9, 2019, 2:31pm UTC](https://root-forum.cern.ch/t/error-rectangles-filled-incorectly/35070/4 "2019-07-09T14:31:17Z")

</div>

An alternative is to use [TGraphErrors](https://root.cern.ch/doc/master/classTGraphErrors.html), which should do what you want; something like:

```auto
  TGraphErrors *gr = new TGraphErrors(n, x, y, x_err, y_err);
  gr->SetLineColor(kGray);
  gr->SetLineWidth(2);
  gr->SetFillStyle(3001);
  gr->SetFillColor(kGray);
  gr->Draw("ALP2");

```

---

<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:** [July 9, 2019, 2:52pm UTC](https://root-forum.cern.ch/t/error-rectangles-filled-incorectly/35070/5 "2019-07-09T14:52:26Z")

</div>

It seems ok for me:

```auto
void errorproblem(){
   auto h = new TH1F("h","h",100,0,1);
   h->FillRandom("gaus");
   h->SetFillColor(kGray); //setting filling color
   h->Draw(" E2");
}

```

 ![40](https://root-forum.cern.ch/uploads/default/original/3X/d/6/d6409f5ee5b65555608a10f3acb2a63f1b05f59b.jpeg)

---

<div class="post-metadata">

**Author:** ![Marta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/marta/32/18269_2.png) [@Marta](https://root-forum.cern.ch/u/Marta)\
**Post date:** [July 9, 2019, 3:58pm UTC](https://root-forum.cern.ch/t/error-rectangles-filled-incorectly/35070/6 "2019-07-09T15:58:25Z")

</div>

Thank you! The problem was the `"hist"` option in Draw(). When I omit that, it makes the errors right.  
The downside to this is the fact that to have the lines there, I must now draw the histogram twice, and thus define and set everything twice, but that is manageable.

---

<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:** [July 10, 2019, 6:27am UTC](https://root-forum.cern.ch/t/error-rectangles-filled-incorectly/35070/7 "2019-07-10T06:27:46Z")

</div>

Note also you should not use SAME when you plot the first histogram.  
Can you should me how you final plot should looks like ?  
I may find an easier solution.

---

<div class="post-metadata">

**Author:** ![Marta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/marta/32/18269_2.png) [@Marta](https://root-forum.cern.ch/u/Marta)\
**Post date:** [July 10, 2019, 7:22am UTC](https://root-forum.cern.ch/t/error-rectangles-filled-incorectly/35070/8 "2019-07-10T07:22:35Z")

</div>

Thanks.  
If you find easier solution, that would be perfect! This is how it should look like (and which I am able to achieve, but in quite lengthy manner)  
[ff\_pt\_1.pdf](https://root-forum.cern.ch/uploads/short-url/xACEyh9rMuG4ntMVQJFvdsEd2VL.pdf) (13.6 KB)

---

<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:** [July 10, 2019, 7:47am UTC](https://root-forum.cern.ch/t/error-rectangles-filled-incorectly/35070/9 "2019-07-10T07:47:37Z")

</div>

The way to do it will be:

```auto
void errorproblem(){
   auto h = new TH1F("h","h",100,0,1);
   h->FillRandom("gaus");
   h->SetFillColor(kGray); //setting filling color
   h->Draw("E2");
   TH1 *hh = h->DrawCopy("HIST SAME");
   hh->SetFillStyle(0);
   hh->SetLineColor(kRed);
   hh->SetLineWidth(3);
}

```

May be you found the same solution.

 ![17](https://root-forum.cern.ch/uploads/default/original/3X/3/6/36fa82d127b85df6dfc79d170f466132a752cb8b.jpeg)

---

<div class="post-metadata">

**Author:** ![Marta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/marta/32/18269_2.png) [@Marta](https://root-forum.cern.ch/u/Marta)\
**Post date:** [July 10, 2019, 11:40am UTC](https://root-forum.cern.ch/t/error-rectangles-filled-incorectly/35070/10 "2019-07-10T11:40:07Z")

</div>

Thank you, I did not realize there is DrawCopy, I was creating the histogram again from scratch. This will save me a quite a number of lines of code, thanks!
