Logo ROOT   6.07/09
Reference Guide
graphShade.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_graphs
3 /// \notebook
4 /// Show how to shade an area between two graphs
5 ///
6 /// \macro_image
7 /// \macro_code
8 ///
9 /// \author Rene Brun
10 
11 void graphShade() {
12  TCanvas *c1 = new TCanvas("c1",
13  "A Simple Graph Example",200,10,700,500);
14 
15  c1->SetGrid();
16  c1->DrawFrame(0,0,2.2,12);
17 
18  const Int_t n = 20;
19  Double_t x[n], y[n],ymin[n], ymax[n];
20  Int_t i;
21  for (i=0;i<n;i++) {
22  x[i] = 0.1+i*0.1;
23  ymax[i] = 10*sin(x[i]+0.2);
24  ymin[i] = 8*sin(x[i]+0.1);
25  y[i] = 9*sin(x[i]+0.15);
26  }
27  TGraph *grmin = new TGraph(n,x,ymin);
28  TGraph *grmax = new TGraph(n,x,ymax);
29  TGraph *gr = new TGraph(n,x,y);
30  TGraph *grshade = new TGraph(2*n);
31  for (i=0;i<n;i++) {
32  grshade->SetPoint(i,x[i],ymax[i]);
33  grshade->SetPoint(n+i,x[n-i-1],ymin[n-i-1]);
34  }
35  grshade->SetFillStyle(3013);
36  grshade->SetFillColor(16);
37  grshade->Draw("f");
38  grmin->Draw("l");
39  grmax->Draw("l");
40  gr->SetLineWidth(4);
41  gr->SetMarkerColor(4);
42  gr->SetMarkerStyle(21);
43  gr->Draw("CP");
44 }
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:49
return c1
Definition: legend1.C:41
float ymin
Definition: THbookFile.cxx:93
TH1F * DrawFrame(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax, const char *title="")
Draw an empty pad frame with X and Y axis.
Definition: TPad.cxx:1491
int Int_t
Definition: RtypesCore.h:41
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition: TAttFill.h:44
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:747
Double_t x[n]
Definition: legend1.C:17
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:318
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition: TAttMarker.h:43
double sin(double)
float ymax
Definition: THbookFile.cxx:93
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:42
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition: TAttMarker.h:45
TGraphErrors * gr
Definition: legend1.C:25
The Canvas class.
Definition: TCanvas.h:41
double Double_t
Definition: RtypesCore.h:55
Double_t y[n]
Definition: legend1.C:17
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
Definition: TGraph.cxx:2150
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:53
const Int_t n
Definition: legend1.C:16