ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
gerrors2.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_graphs
3 /// Draw two graphs with error bars
4 ///
5 /// \macro_image
6 /// \macro_code
7 ///
8 /// \author Rene Brun
9 
10 void gerrors2() {
11  TCanvas *c1 = new TCanvas("c1","gerrors2",200,10,700,500);
12  c1->SetFillColor(42);
13  c1->SetGrid();
14 
15  // draw a frame to define the range
16  TH1F *hr = c1->DrawFrame(-0.4,0,1.2,12);
17  hr->SetXTitle("X title");
18  hr->SetYTitle("Y title");
19  c1->GetFrame()->SetFillColor(21);
20  c1->GetFrame()->SetBorderSize(12);
21 
22  // create first graph
23  const Int_t n1 = 10;
24  Double_t x1[] = {-0.22, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95};
25  Double_t y1[] = {1,2.9,5.6,7.4,9,9.6,8.7,6.3,4.5,1};
26  Double_t ex1[] = {.05,.1,.07,.07,.04,.05,.06,.07,.08,.05};
27  Double_t ey1[] = {.8,.7,.6,.5,.4,.4,.5,.6,.7,.8};
28  TGraphErrors *gr1 = new TGraphErrors(n1,x1,y1,ex1,ey1);
29  gr1->SetMarkerColor(kBlue);
30  gr1->SetMarkerStyle(21);
31  gr1->Draw("LP");
32 
33  // create second graph
34  const Int_t n2 = 10;
35  Float_t x2[] = {-0.28, 0.005, 0.19, 0.29, 0.45, 0.56,0.65,0.80,0.90,1.01};
36  Float_t y2[] = {0.82,3.86,7,9,10,10.55,9.64,7.26,5.42,2};
37  Float_t ex2[] = {.04,.12,.08,.06,.05,.04,.07,.06,.08,.04};
38  Float_t ey2[] = {.6,.8,.7,.4,.3,.3,.4,.5,.6,.7};
39  TGraphErrors *gr2 = new TGraphErrors(n2,x2,y2,ex2,ey2);
40  gr2->SetMarkerColor(kRed);
41  gr2->SetMarkerStyle(20);
42  gr2->Draw("LP");
43 }
float Float_t
Definition: RtypesCore.h:53
Definition: Rtypes.h:61
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
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:570
int Int_t
Definition: RtypesCore.h:41
virtual void SetYTitle(const char *title)
Definition: TH1.h:409
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:740
TFrame * GetFrame()
Get frame.
Definition: TPad.cxx:2729
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
virtual void SetBorderSize(Short_t bordersize)
Definition: TWbox.h:63
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 SetXTitle(const char *title)
Definition: TH1.h:408
A TGraphErrors is a TGraph with error bars.
Definition: TGraphErrors.h:28
Definition: Rtypes.h:61