# How to correctly draw a TH2 Polar plot

Hi!

I’m trying to produce a TH2 polar plot:

``````void test () {

gStyle->SetOptStat(0);
Double_t theta[] = {30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330, 360};
double r = 0.06;

TCanvas* c = new TCanvas("c", "c", 800, 800);

TH2D* d = new TH2D("d", "", 2, -1, 1, 2, -1, 1);
TH2D* h = new TH2D("p", "", 12, 0, 360, 12, 0, 1);

d->GetXaxis()->SetLabelSize(0);
d->GetYaxis()->SetLabelSize(0);

for (double t : theta) {
h->Fill(t, r);
r += 0.06;
}

d->Draw("COL");
h->Draw("col pol same");
}
``````

The output:

I digged a bit in the forum here and I couldn’t find a way to avoid a dummy TH2 in order to draw the polar plot correctly. Is it mandatory?
Above all, why do I get a doily instead of the funny iridescent circle I want?

PS:
Sorry for bothering over and over, almost every single day.

I must admit I do not really understand the result you get … May be using the POL option on Lego would be better ?

``````{
gStyle->SetOptStat(0);
Double_t theta[] = {30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330, 360};
double r = 0.06;

TCanvas* c = new TCanvas("c", "c", 800, 800);
c->SetTheta(90);
c->SetPhi(0.);

TH2D* h = new TH2D("p", "", 12, 0, 360, 12, 0, 1);

for (double t : theta) {
h->Fill(t, r);
r += 0.06;
}

h->Draw("lego2 pol");
}
``````

1 Like

That’s much better.
Is it possible to get circular sectors instead of triangles?

This is because you have a few bins only… with more bins it will be more circular.

Uhm…
Optical effects then. One last thing: how to rotate the circle by 90 deg clockwise?

``````   c->SetPhi(270.);
``````
1 Like

Thank you, couet. This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.