ROOT logo

From $ROOTSYS/tutorials/graphs/graphpolar.C

//Create and draw a polar graph
//Author: Olivier Couet
   
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 xmin=0;
   Double_t xmax=TMath::Pi()*2;

   Double_t x[1000];
   Double_t y[1000];
   Double_t x1[20];
   Double_t y1[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(0.2);
   grP->SetFillStyle(3012);
   grP->SetFillColor(2);
   grP->Draw("AFL");

   for (Int_t ipt = 0; ipt < 20; ipt++){
      x1[ipt] = x[1000/20*ipt];
      y1[ipt] = y[1000/20*ipt];
   }

   TGraphPolar * grP1 = new TGraphPolar(20,x1,y1);
   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()->SetRangePolar(-TMath::Pi(),TMath::Pi());
   grP1->GetPolargram()->SetNdivPolar(703);
   grP1->GetPolargram()->SetToRadian();

   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();
   grPE->GetPolargram()->SetToRadian();
}
 graphpolar.C:1
 graphpolar.C:2
 graphpolar.C:3
 graphpolar.C:4
 graphpolar.C:5
 graphpolar.C:6
 graphpolar.C:7
 graphpolar.C:8
 graphpolar.C:9
 graphpolar.C:10
 graphpolar.C:11
 graphpolar.C:12
 graphpolar.C:13
 graphpolar.C:14
 graphpolar.C:15
 graphpolar.C:16
 graphpolar.C:17
 graphpolar.C:18
 graphpolar.C:19
 graphpolar.C:20
 graphpolar.C:21
 graphpolar.C:22
 graphpolar.C:23
 graphpolar.C:24
 graphpolar.C:25
 graphpolar.C:26
 graphpolar.C:27
 graphpolar.C:28
 graphpolar.C:29
 graphpolar.C:30
 graphpolar.C:31
 graphpolar.C:32
 graphpolar.C:33
 graphpolar.C:34
 graphpolar.C:35
 graphpolar.C:36
 graphpolar.C:37
 graphpolar.C:38
 graphpolar.C:39
 graphpolar.C:40
 graphpolar.C:41
 graphpolar.C:42
 graphpolar.C:43
 graphpolar.C:44
 graphpolar.C:45
 graphpolar.C:46
 graphpolar.C:47
 graphpolar.C:48
 graphpolar.C:49
 graphpolar.C:50
 graphpolar.C:51
 graphpolar.C:52
 graphpolar.C:53
 graphpolar.C:54
 graphpolar.C:55
 graphpolar.C:56
 graphpolar.C:57
 graphpolar.C:58
 graphpolar.C:59
 graphpolar.C:60
 graphpolar.C:61
 graphpolar.C:62
 graphpolar.C:63
 graphpolar.C:64
 graphpolar.C:65
 graphpolar.C:66
 graphpolar.C:67
 graphpolar.C:68
 graphpolar.C:69
 graphpolar.C:70
 graphpolar.C:71
 graphpolar.C:72
 graphpolar.C:73
 graphpolar.C:74
 graphpolar.C:75
 graphpolar.C:76
 graphpolar.C:77
thumb