Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
gr106_exclusiongraph.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphs
3/// \notebook
4/// \preview Draw three graphs with an exclusion zone.
5///
6/// The shaded areas are obtained with a fill for the graph and controlled with `SetLineWidth`.
7/// `SetLineWidth` for exclusion graphs is explained in the [TGraphPainter documentation](https://root.cern/doc/master/classTGraphPainter.html#GrP2)
8///
9/// As the graphs will be superposed on drawing, we add them to a [TMultiGraph](https://root.cern/doc/master/classTMultiGraph.html) and then draw this one.
10///
11/// \macro_image
12/// \macro_code
13/// \author Olivier Couet
14
15TCanvas *gr106_exclusiongraph() {
16 TCanvas *c1 = new TCanvas("c1","Exclusion graph examples",200,10,600,400);
17 c1->SetGrid();
18
19 TMultiGraph *mg = new TMultiGraph();
20 mg->SetTitle("Exclusion graphs");
21
22 const Int_t n = 35;
23 Double_t xvalues1[n], xvalues2[n], xvalues3[n], yvalues1[n], yvalues2[n], yvalues3[n];
24 for (Int_t i=0;i<n;i++) {
25 xvalues1[i] = i*0.1;
26 xvalues2[i] = xvalues1[i];
27 xvalues3[i] = xvalues1[i]+.5;
28 yvalues1[i] = 10*sin(xvalues1[i]);
29 yvalues2[i] = 10*cos(xvalues1[i]);
30 yvalues3[i] = 10*sin(xvalues1[i])-2;
31 }
32
33 // See explanation for SetLineWidth above
34 TGraph *gr1 = new TGraph(n,xvalues1,yvalues1);
35 gr1->SetLineColor(2);
36 gr1->SetLineWidth(1504);
37 gr1->SetFillStyle(3005);
38
39 TGraph *gr2 = new TGraph(n,xvalues2,yvalues2);
40 gr2->SetLineColor(4);
41 gr2->SetLineWidth(-2002);
42 gr2->SetFillStyle(3004);
43 gr2->SetFillColor(9);
44
45 TGraph *gr3 = new TGraph(n,xvalues3,yvalues3);
46 gr3->SetLineColor(5);
47 gr3->SetLineWidth(-802);
48 gr3->SetFillStyle(3002);
49 gr3->SetFillColor(2);
50
51 mg->Add(gr1);
52 mg->Add(gr2);
53 mg->Add(gr3);
54 mg->Draw("AC");
55
56 return c1;
57}
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:40
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition TAttFill.h:42
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:47
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:44
The Canvas class.
Definition TCanvas.h:23
virtual void Add(TGraph *graph, Option_t *chopt="")
void Draw(Option_t *chopt="") override
Default Draw method for all objects.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:173
RVec< PromoteType< T > > cos(const RVec< T > &v)
Definition RVec.hxx:1848
RVec< PromoteType< T > > sin(const RVec< T > &v)
Definition RVec.hxx:1847
return c1
Definition legend1.C:41
const Int_t n
Definition legend1.C:16