# How to fill color in function?

**URL:** <https://root-forum.cern.ch/t/how-to-fill-color-in-function/38450>\
**Category:** Newbie\
**Created:** [March 18, 2020, 8:10am UTC](https://root-forum.cern.ch/t/how-to-fill-color-in-function/38450 "2020-03-18T08:10:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![meu](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/meu/32/20557_2.png) [@meu](https://root-forum.cern.ch/u/meu)\
**Post date:** [March 18, 2020, 8:10am UTC](https://root-forum.cern.ch/t/how-to-fill-color-in-function/38450/1 "2020-03-18T08:10:30Z")

</div>

Hi, Everyone,

I want to fill color in function, then can ROOT do it?

I have sample code making the gaussian.

```auto
{
  TCanvas *c=new TCanvas();
  TF1 *f=new TF1("f", "TMath::Gaus(x)", -6, 6);
  f->Draw();
  return c;
}

```

For example, I want to fill color in the function region rom -1 to 1  
I tried to make another gaussian which have region from -1 to 1 and used SetFillColor.  
But I couldn’t.  
Please help me.

---

<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:** [March 18, 2020, 9:45am UTC](https://root-forum.cern.ch/t/how-to-fill-color-in-function/38450/3 "2020-03-18T09:45:20Z")

</div>

The way to do it would be:

```auto
{
   TF1 *f=new TF1("f", "TMath::Gaus(x)", -6, 6);
   f->SetFillColor(3);
   f->SetFillStyle(1001);
   f->Draw();
}

```

But doing that the function is drawn as a histogram, with steps.  
There is a work around. You can do:

```auto
   f->Draw("LF2");

```

I will apply a fix to draw the filled function that way by default.

---

<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:** [March 18, 2020, 10:23am UTC](https://root-forum.cern.ch/t/how-to-fill-color-in-function/38450/4 "2020-03-18T10:23:03Z")

</div>

I made a PR for that. [https://github.com/root-project/root/pull/5174](https://github.com/root-project/root/pull/5174)  
Thanks.

---

<div class="post-metadata">

**Author:** ![meu](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/meu/32/20557_2.png) [@meu](https://root-forum.cern.ch/u/meu)\
**Post date:** [March 18, 2020, 11:18am UTC](https://root-forum.cern.ch/t/how-to-fill-color-in-function/38450/5 "2020-03-18T11:18:12Z")

</div>

Thanks for suggesting my question as Pull requests!

If we fill the gaussian, it is clear to fill area from y=0 to from Gauss function.  
If we can fill in between two functions area etc in the future, I think it looks useful.

I look forward to using renewal function!

---

<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:** [March 18, 2020, 12:53pm UTC](https://root-forum.cern.ch/t/how-to-fill-color-in-function/38450/6 "2020-03-18T12:53:03Z")

</div>

> [@meu](#):
>
> I look forward to using renewal function!

Meanwhile you can use the workaround I sent you

> [@meu](#):
>
> fill in between two functions

Can you provide an example showing the area to be filled ?

---

<div class="post-metadata">

**Author:** ![meu](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/meu/32/20557_2.png) [@meu](https://root-forum.cern.ch/u/meu)\
**Post date:** [March 18, 2020, 1:47pm UTC](https://root-forum.cern.ch/t/how-to-fill-color-in-function/38450/7 "2020-03-18T13:47:16Z")

</div>

The reason why I made this question starts from “drawing Gaussian more than σ region”.

So, I thought I use two function about x=σ and y=C_exp[x^2/2_σ^2], then it may represent fmore than σ filled region.

---

<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:** [March 18, 2020, 2:18pm UTC](https://root-forum.cern.ch/t/how-to-fill-color-in-function/38450/8 "2020-03-18T14:18:10Z")

</div>

Ok … a small script would help.
