ROOT logo
//Show how to shade an area between two graphs
//Author: Rene Brun
void graphShade() {
   TCanvas *c1 = new TCanvas("c1",
      "A Simple Graph Example",200,10,700,500);

   c1->SetGrid();
   c1->DrawFrame(0,0,2.2,12);
   
   const Int_t n = 20;
   Double_t x[n], y[n],ymin[n], ymax[n];
   Int_t i;
   for (i=0;i<n;i++) {
     x[i] = 0.1+i*0.1;
     ymax[i] = 10*sin(x[i]+0.2);
     ymin[i] = 8*sin(x[i]+0.1);
     y[i] = 9*sin(x[i]+0.15);
   }
   TGraph *grmin = new TGraph(n,x,ymin);
   TGraph *grmax = new TGraph(n,x,ymax);
   TGraph *gr    = new TGraph(n,x,y);
   TGraph *grshade = new TGraph(2*n);
   for (i=0;i<n;i++) {
      grshade->SetPoint(i,x[i],ymax[i]);
      grshade->SetPoint(n+i,x[n-i-1],ymin[n-i-1]);
   }
   grshade->SetFillStyle(3013);
   grshade->SetFillColor(16);
   grshade->Draw("f");
   grmin->Draw("l");
   grmax->Draw("l");
   gr->SetLineWidth(4);
   gr->SetMarkerColor(4);
   gr->SetMarkerStyle(21);
   gr->Draw("CP");
}
 graphShade.C:1
 graphShade.C:2
 graphShade.C:3
 graphShade.C:4
 graphShade.C:5
 graphShade.C:6
 graphShade.C:7
 graphShade.C:8
 graphShade.C:9
 graphShade.C:10
 graphShade.C:11
 graphShade.C:12
 graphShade.C:13
 graphShade.C:14
 graphShade.C:15
 graphShade.C:16
 graphShade.C:17
 graphShade.C:18
 graphShade.C:19
 graphShade.C:20
 graphShade.C:21
 graphShade.C:22
 graphShade.C:23
 graphShade.C:24
 graphShade.C:25
 graphShade.C:26
 graphShade.C:27
 graphShade.C:28
 graphShade.C:29
 graphShade.C:30
 graphShade.C:31
 graphShade.C:32
 graphShade.C:33
 graphShade.C:34
 graphShade.C:35
 graphShade.C:36
 graphShade.C:37
thumb