Shading between functions

I need to shade the area between some plotted functions, is there a good way of doing this? I’ve attached an example of what I have right now (funcs1.eps.gz) and what I need to make it look like (funcs1_shaded.eps.gz).
funcs1_shaded.eps.gz (20.4 KB)
funcs1.eps.gz (11.6 KB)

see example in attachment. Replace the filling of the TGraphs by calls to your function values on both sides.

Rene
grshade.C (871 Bytes)

Thanks for your prompt response, but I use the functions in conjunction with TF1 objects:

TF1* f1[4], f2[4], f3[4];

for(int i=0; i<4; i++){
f1[i] = new TF1("f1"+i,fcalc,1e-4,0.99,3);
f2[i] = new TF1("f1"+i,fcalc,1e-4,0.99,3);
f3[i] = new TF1("f1"+i,fcalc,1e-4,0.99,3);

f1[i]->SetParameters(Q2[i],0,0);
f2[i]->SetParameters(Q2[i],1,0);
f3[i]->SetParameters(Q2[i],2,0);

f1[i]->Draw();
f2[i]->Draw("same");
f3[i]->Draw("same");

It’s these TF1 functions which produce the three curves, I need to be able to shade the region between the three though. How can that be achieved?

see an example below along the lines along of what I was telling you to do above.

Rene

[code]void shade(TCanvas *c1, TF1 *f1, TF1 *f2, TF1 *f3) {
//shade the area between f1 and f2 and draw f3 on top

//create a TGraph to store the function values
//shaded area is the fill/color/style of f1
TGraph *gr = new TGraph();
gr->SetFillColor(f1->GetFillColor());
gr->SetFillStyle(f1->GetFillStyle());
f3->Draw(“l”);
c1->Update();
//get picture range
Double_t xmin = c1->GetUxmin();
Double_t xmax = c1->GetUxmax();
Double_t ymin = c1->GetUymin();
Double_t ymax = c1->GetUymax();

//process first function
Int_t npx = f3->GetNpx();
Int_t npoints=0;
Double_t dx = (xmax-xmin)/npx;
Double_t x = xmin+0.5dx;
while (x <= xmax) {
Double_t y = f1->Eval(x);
if (y < ymin) y = ymin;
if (y > ymax) y = ymax;
gr->SetPoint(npoints,x,y);
npoints++;
x += dx;
}
//process second function
x = xmax-0.5
dx;
while (x >= xmin) {
Double_t y = f2->Eval(x);
if (y < ymin) y = ymin;
if (y > ymax) y = ymax;
gr->SetPoint(npoints,x,y);
npoints++;
x -= dx;
}
gr->Draw(“f”); //draw graph with fill area option
f3->Draw(“lsame”); //superimpose function
}

void fshade() {
TF1 *f1 = new TF1(“f1”,“1/x +0.04”,1,5);
TF1 *f2 = new TF1(“f2”,“1/x -0.04”,1,5);
TF1 *f3 = new TF1(“f3”,“1/x +0”,1,5);
f1->SetFillColor(kBlue);
f1->SetFillStyle(3001);
TCanvas *c1 = new TCanvas(“c1”);
shade(c1,f1,f2,f3);
}
[/code]