ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
graphShade.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_graphs
3 /// Show how to shade an area between two graphs
4 ///
5 /// \macro_image
6 /// \macro_code
7 ///
8 /// \author Rene Brun
9 
10 void graphShade() {
11  TCanvas *c1 = new TCanvas("c1",
12  "A Simple Graph Example",200,10,700,500);
13 
14  c1->SetGrid();
15  c1->DrawFrame(0,0,2.2,12);
16 
17  const Int_t n = 20;
18  Double_t x[n], y[n],ymin[n], ymax[n];
19  Int_t i;
20  for (i=0;i<n;i++) {
21  x[i] = 0.1+i*0.1;
22  ymax[i] = 10*sin(x[i]+0.2);
23  ymin[i] = 8*sin(x[i]+0.1);
24  y[i] = 9*sin(x[i]+0.15);
25  }
26  TGraph *grmin = new TGraph(n,x,ymin);
27  TGraph *grmax = new TGraph(n,x,ymax);
28  TGraph *gr = new TGraph(n,x,y);
29  TGraph *grshade = new TGraph(2*n);
30  for (i=0;i<n;i++) {
31  grshade->SetPoint(i,x[i],ymax[i]);
32  grshade->SetPoint(n+i,x[n-i-1],ymin[n-i-1]);
33  }
34  grshade->SetFillStyle(3013);
35  grshade->SetFillColor(16);
36  grshade->Draw("f");
37  grmin->Draw("l");
38  grmax->Draw("l");
39  gr->SetLineWidth(4);
40  gr->SetMarkerColor(4);
41  gr->SetMarkerStyle(21);
42  gr->Draw("CP");
43 }
virtual void SetLineWidth(Width_t lwidth)
Definition: TAttLine.h:57
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:1475
int Int_t
Definition: RtypesCore.h:41
virtual void SetFillStyle(Style_t fstyle)
Definition: TAttFill.h:52
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:740
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:326
virtual void SetMarkerColor(Color_t mcolor=1)
Definition: TAttMarker.h:51
double sin(double)
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
virtual void SetMarkerStyle(Style_t mstyle=1)
Definition: TAttMarker.h:53
The Canvas class.
Definition: TCanvas.h:48
double Double_t
Definition: RtypesCore.h:55
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
Definition: TGraph.cxx:2127
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