Logo ROOT  
Reference Guide
graphpolar.C File Reference

Detailed Description

View in nbviewer Open in SWAN Create and draw a polar graph.

void graphpolar()
{
// Illustrates how to use TGraphPolar
TCanvas * CPol = new TCanvas("CPol","TGraphPolar Examples",1200,600);
CPol->Divide(2,1);
CPol->cd(1);
Double_t x[1000];
Double_t y[1000];
Double_t xval1[20];
Double_t yval1[20];
TF1 * fplot = new TF1("fplot","cos(2*x)*cos(20*x)",xmin,xmax);
for (Int_t ipt = 0; ipt < 1000; ipt++){
x[ipt] = ipt*(xmax-xmin)/1000+xmin;
y[ipt] = fplot->Eval(x[ipt]);
}
TGraphPolar * grP = new TGraphPolar(1000,x,y);
grP->SetLineColor(2);
grP->SetLineWidth(2);
grP->SetFillStyle(3012);
grP->SetFillColor(2);
grP->Draw("AFL");
for (Int_t ipt = 0; ipt < 20; ipt++){
xval1[ipt] = x[1000/20*ipt];
yval1[ipt] = y[1000/20*ipt];
}
TGraphPolar * grP1 = new TGraphPolar(20,xval1,yval1);
grP1->SetMarkerStyle(29);
grP1->SetMarkerSize(2);
grP1->SetMarkerColor(4);
grP1->SetLineColor(4);
grP1->Draw("CP");
// Update, otherwise GetPolargram returns 0
CPol->Update();
grP1->GetPolargram()->SetTextColor(8);
grP1->GetPolargram()->SetNdivPolar(703);
CPol->cd(2);
Double_t x2[30];
Double_t y2[30];
Double_t ex[30];
Double_t ey[30];
for (Int_t ipt = 0; ipt < 30; ipt++){
x2[ipt] = x[1000/30*ipt];
y2[ipt] = 1.2 + 0.4*sin(TMath::Pi()*2*ipt/30);
ex[ipt] = 0.2+0.1*cos(2*TMath::Pi()/30*ipt);
ey[ipt] = 0.2;
}
TGraphPolar * grPE = new TGraphPolar(30,x2,y2,ex,ey);
grPE->SetMarkerStyle(22);
grPE->SetMarkerSize(1.5);
grPE->SetMarkerColor(5);
grPE->SetLineColor(6);
grPE->SetLineWidth(2);
grPE->Draw("EP");
CPol->Update();
grPE->GetPolargram()->SetTextSize(0.03);
grPE->GetPolargram()->SetTwoPi();
}
Author
Olivier Couet

Definition in file graphpolar.C.

ex
Double_t ex[n]
Definition: legend1.C:17
xmax
float xmax
Definition: THbookFile.cxx:95
Int_t
int Int_t
Definition: RtypesCore.h:45
sin
double sin(double)
x
Double_t x[n]
Definition: legend1.C:17
cos
double cos(double)
TPad::Divide
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:1166
TGraphPolargram::SetNdivPolar
void SetNdivPolar(Int_t Ndiv=508)
Set the number of Polar divisions: enter a number ij with 0<i<99 and 0<j<99.
Definition: TGraphPolargram.cxx:773
TGraphPolargram::SetToRadian
void SetToRadian()
The Polar circle is labelled using radian.
Definition: TGraphPolargram.cxx:934
TGraphPolar
Definition: TGraphPolar.h:23
TMath::Pi
constexpr Double_t Pi()
Definition: TMath.h:43
TGraphPolargram::SetRangePolar
void SetRangePolar(Double_t tmin, Double_t tmax)
Allows to change range Polar.
Definition: TGraphPolargram.cxx:874
xmin
float xmin
Definition: THbookFile.cxx:95
TCanvas::cd
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:704
TGraphPolar::GetPolargram
TGraphPolargram * GetPolargram()
Definition: TGraphPolar.h:46
y
Double_t y[n]
Definition: legend1.C:17
ey
Double_t ey[n]
Definition: legend1.C:17
Double_t
double Double_t
Definition: RtypesCore.h:59
TCanvas
Definition: TCanvas.h:23
TF1::Eval
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:1450
TGraphPolar::Draw
void Draw(Option_t *options="")
Draw TGraphPolar.
Definition: TGraphPolar.cxx:100
TCanvas::Update
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2500
x2
static const double x2[5]
Definition: RooGaussKronrodIntegrator1D.cxx:364
TF1
1-Dim function class
Definition: TF1.h:212
TGraphPolargram::SetTwoPi
void SetTwoPi()
Set range from 0 to 2*pi.
Definition: TGraphPolargram.cxx:945