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 File Reference

Detailed Description

View in nbviewer Open in SWAN
Show how to shade an area between two graphs.

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); //Y points for the upper graph
ymin[i] = 8*sin(x[i]+0.1); //Y point for the lower graph
y[i] = 9*sin(x[i]+0.15);
}
TGraph *grmin = new TGraph(n,x,ymin); //Bottom graph
TGraph *grmax = new TGraph(n,x,ymax); //Upper graph
TGraph *gr = new TGraph(n,x,y); //Middle graph
TGraph *grshade = new TGraph(2*n); //Create a graph to represent the shaded region between the upper and lower graphs
for (i=0;i<n;i++) { //Populate points in the shaded graph
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"); //Draw the shaded area with "f" option (filled graph)
grmin->Draw("l");
grmax->Draw("l");
gr->Draw("CP");
}
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
Author
Rene Brun

Definition in file gr101_shade_area.C.