How to fill color in function?

Hi, Everyone,

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

I have sample code making the gaussian.

  TCanvas *c=new TCanvas();
  TF1 *f=new TF1("f", "TMath::Gaus(x)", -6, 6);
  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.

The way to do it would be:

   TF1 *f=new TF1("f", "TMath::Gaus(x)", -6, 6);

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


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

1 Like

I made a PR for that.


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!

Meanwhile you can use the workaround I sent you

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

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=Cexp[x^2/2σ^2], then it may represent fmore than σ filled region.

Ok … a small script would help.