Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
gr101_shade_area.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphs
3/// \notebook
4/// \preview Show how to shade an area between two graphs.
5///
6/// \macro_image
7/// \macro_code
8///
9/// \author Rene Brun
10
11void gr101_shade_area() {
12 TCanvas *c1 = new TCanvas("c1","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); //Y points for the upper graph
23 ymin[i] = 8*sin(x[i]+0.1); //Y point for the lower graph
24 y[i] = 9*sin(x[i]+0.15);
25 }
26 TGraph *grmin = new TGraph(n,x,ymin); //Bottom graph
27 TGraph *grmax = new TGraph(n,x,ymax); //Upper graph
28 TGraph *gr = new TGraph(n,x,y); //Middle graph
29 TGraph *grshade = new TGraph(2*n); //Create a graph to represent the shaded region between the upper and lower graphs
30 for (i=0;i<n;i++) { //Populate points in the shaded graph
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"); //Draw the shaded area with "f" option (filled graph)
37 grmin->Draw("l");
38 grmax->Draw("l");
39 gr->SetLineWidth(4);
41 gr->SetMarkerStyle(21);
42 gr->Draw("CP");
43}
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
float ymin
float ymax
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:45
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:39
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:41
The Canvas class.
Definition TCanvas.h:23
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
void Draw(Option_t *chopt="") override
Draw this graph with its current attributes.
Definition TGraph.cxx:833
Double_t y[n]
Definition legend1.C:17
return c1
Definition legend1.C:41
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
TGraphErrors * gr
Definition legend1.C:25