ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
graphpolar.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_graphs
3 /// Create and draw a polar graph.
4 /// \macro_image
5 /// \macro_code
6 ///
7 /// \author Olivier Couet
8 
9 void graphpolar()
10 {
11  // Illustrates how to use TGraphPolar
12 
13  TCanvas * CPol = new TCanvas("CPol","TGraphPolar Examples",1200,600);
14  CPol->Divide(2,1);
15  CPol->cd(1);
16 
17  Double_t xmin=0;
18  Double_t xmax=TMath::Pi()*2;
19 
20  Double_t x[1000];
21  Double_t y[1000];
22  Double_t x1[20];
23  Double_t y1[20];
24 
25  TF1 * fplot = new TF1("fplot","cos(2*x)*cos(20*x)",xmin,xmax);
26 
27  for (Int_t ipt = 0; ipt < 1000; ipt++){
28  x[ipt] = ipt*(xmax-xmin)/1000+xmin;
29  y[ipt] = fplot->Eval(x[ipt]);
30  }
31 
32  TGraphPolar * grP = new TGraphPolar(1000,x,y);
33  grP->SetLineColor(2);
34  grP->SetLineWidth(2);
35  grP->SetFillStyle(3012);
36  grP->SetFillColor(2);
37  grP->Draw("AFL");
38 
39  for (Int_t ipt = 0; ipt < 20; ipt++){
40  x1[ipt] = x[1000/20*ipt];
41  y1[ipt] = y[1000/20*ipt];
42  }
43 
44  TGraphPolar * grP1 = new TGraphPolar(20,x1,y1);
45  grP1->SetMarkerStyle(29);
46  grP1->SetMarkerSize(2);
47  grP1->SetMarkerColor(4);
48  grP1->SetLineColor(4);
49  grP1->Draw("CP");
50 
51  // Update, otherwise GetPolargram returns 0
52  CPol->Update();
53  grP1->GetPolargram()->SetTextColor(8);
55  grP1->GetPolargram()->SetNdivPolar(703);
56  grP1->GetPolargram()->SetToRadian();
57 
58  CPol->cd(2);
59  Double_t x2[30];
60  Double_t y2[30];
61  Double_t ex[30];
62  Double_t ey[30];
63  for (Int_t ipt = 0; ipt < 30; ipt++){
64  x2[ipt] = x[1000/30*ipt];
65  y2[ipt] = 1.2 + 0.4*sin(TMath::Pi()*2*ipt/30);
66  ex[ipt] = 0.2+0.1*cos(2*TMath::Pi()/30*ipt);
67  ey[ipt] = 0.2;
68  }
69 
70  TGraphPolar * grPE = new TGraphPolar(30,x2,y2,ex,ey);
71  grPE->SetMarkerStyle(22);
72  grPE->SetMarkerSize(1.5);
73  grPE->SetMarkerColor(5);
74  grPE->SetLineColor(6);
75  grPE->SetLineWidth(2);
76  grPE->Draw("EP");
77  CPol->Update();
78  grPE->GetPolargram()->SetTextSize(0.03);
79  grPE->GetPolargram()->SetTwoPi();
80  grPE->GetPolargram()->SetToRadian();
81 }
virtual void SetLineWidth(Width_t lwidth)
Definition: TAttLine.h:57
void SetToRadian()
The Polar circle is labelled using radian.
float xmin
Definition: THbookFile.cxx:93
void SetTwoPi()
Set range from 0 to 2*pi.
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
int Int_t
Definition: RtypesCore.h:41
virtual void SetFillStyle(Style_t fstyle)
Definition: TAttFill.h:52
double cos(double)
virtual void SetMarkerColor(Color_t mcolor=1)
Definition: TAttMarker.h:51
TGraphPolargram * GetPolargram()
Definition: TGraphPolar.h:55
double sin(double)
virtual void SetLineColor(Color_t lcolor)
Definition: TAttLine.h:54
To draw a polar graph.
Definition: TGraphPolar.h:38
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
virtual void SetMarkerStyle(Style_t mstyle=1)
Definition: TAttMarker.h:53
virtual void SetMarkerSize(Size_t msize=1)
Definition: TAttMarker.h:54
Double_t Pi()
Definition: TMath.h:44
The Canvas class.
Definition: TCanvas.h:48
double Double_t
Definition: RtypesCore.h:55
void SetNdivPolar(Int_t Ndiv=508)
Set the number of Polar divisions: enter a number ij with 0<i<99 and 0<j<99.
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1073
void Draw(Option_t *options="")
Draw TGraphPolar.
1-Dim function class
Definition: TF1.h:149
virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
Evaluate this function.
Definition: TF1.cxx:1162
virtual void SetTextColor(Color_t tcolor=1)
Definition: TAttText.h:57
virtual void SetTextSize(Float_t tsize=1)
Definition: TAttText.h:60
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2179
void SetRangePolar(Double_t tmin, Double_t tmax)
Allows to change range Polar.