Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
graphpolar.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphs
3/// \notebook
4/// Create and draw a polar graph.
5///
6/// \macro_image
7/// \macro_code
8///
9/// \author Olivier Couet
10
11void graphpolar()
12{
13 // Illustrates how to use TGraphPolar
14
15 TCanvas * CPol = new TCanvas("CPol","TGraphPolar Examples",1200,600);
16 CPol->Divide(2,1);
17 CPol->cd(1);
18
19 Double_t xmin=0;
21
22 Double_t x[1000];
23 Double_t y[1000];
24 Double_t xval1[20];
25 Double_t yval1[20];
26
27 TF1 * fplot = new TF1("fplot","cos(2*x)*cos(20*x)",xmin,xmax);
28
29 for (Int_t ipt = 0; ipt < 1000; ipt++){
30 x[ipt] = ipt*(xmax-xmin)/1000+xmin;
31 y[ipt] = fplot->Eval(x[ipt]);
32 }
33
34 TGraphPolar * grP = new TGraphPolar(1000,x,y);
35 grP->SetLineColor(2);
36 grP->SetLineWidth(2);
37 grP->SetFillStyle(3012);
38 grP->SetFillColor(2);
39 grP->Draw("AFL");
40
41 for (Int_t ipt = 0; ipt < 20; ipt++){
42 xval1[ipt] = x[1000/20*ipt];
43 yval1[ipt] = y[1000/20*ipt];
44 }
45
46 TGraphPolar * grP1 = new TGraphPolar(20,xval1,yval1);
47 grP1->SetMarkerStyle(29);
48 grP1->SetMarkerSize(2);
49 grP1->SetMarkerColor(4);
50 grP1->SetLineColor(4);
51 grP1->Draw("CP");
52
53 // Update, otherwise GetPolargram returns 0
54 CPol->Update();
55 if (grP1->GetPolargram()) {
56 grP1->GetPolargram()->SetTextColor(8);
58 grP1->GetPolargram()->SetNdivPolar(703);
59 grP1->GetPolargram()->SetToRadian();
60 }
61
62 CPol->cd(2);
63 Double_t x2[30];
64 Double_t y2[30];
65 Double_t ex[30];
66 Double_t ey[30];
67 for (Int_t ipt = 0; ipt < 30; ipt++){
68 x2[ipt] = x[1000/30*ipt];
69 y2[ipt] = 1.2 + 0.4*sin(TMath::Pi()*2*ipt/30);
70 ex[ipt] = 0.2+0.1*cos(2*TMath::Pi()/30*ipt);
71 ey[ipt] = 0.2;
72 }
73
74 TGraphPolar * grPE = new TGraphPolar(30,x2,y2,ex,ey);
75 grPE->SetMarkerStyle(22);
76 grPE->SetMarkerSize(1.5);
77 grPE->SetMarkerColor(5);
78 grPE->SetLineColor(6);
79 grPE->SetLineWidth(2);
80 grPE->Draw("EP");
81 // Update, otherwise GetPolargram returns 0
82 CPol->Update();
83
84 if (grPE->GetPolargram()) {
85 grPE->GetPolargram()->SetTextSize(0.03);
86 grPE->GetPolargram()->SetTwoPi();
87 grPE->GetPolargram()->SetToRadian();
88 }
89}
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char y2
float xmin
float xmax
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition TAttFill.h:39
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:43
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:38
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:40
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition TAttMarker.h:45
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition TAttText.h:44
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:47
The Canvas class.
Definition TCanvas.h:23
TVirtualPad * cd(Int_t subpadnumber=0) override
Set current canvas & pad.
Definition TCanvas.cxx:716
void Update() override
Update canvas pad buffers.
Definition TCanvas.cxx:2483
1-Dim function class
Definition TF1.h:233
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:1441
To draw a polar graph.
Definition TGraphPolar.h:23
TGraphPolargram * GetPolargram()
Definition TGraphPolar.h:39
void Draw(Option_t *options="") override
Draw TGraphPolar.
void SetRangePolar(Double_t tmin, Double_t tmax)
Allows to change range Polar.
void SetTwoPi()
Set range from 0 to 2*pi.
void SetNdivPolar(Int_t Ndiv=508)
Set the number of Polar divisions: enter a number ij with 0<i<99 and 0<j<99.
void SetToRadian()
The Polar circle is labelled using radian.
void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0) override
Automatic pad generation by division.
Definition TPad.cxx:1153
RVec< PromoteType< T > > cos(const RVec< T > &v)
Definition RVec.hxx:1815
RVec< PromoteType< T > > sin(const RVec< T > &v)
Definition RVec.hxx:1814
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Double_t ey[n]
Definition legend1.C:17
Double_t ex[n]
Definition legend1.C:17
constexpr Double_t Pi()
Definition TMath.h:37