I am attempting to draw a 2d polar histogram using the “pol” option. When I do, the axes appear messed up. The script below generates a 2d plot, then attempts to display it as a polar histogram.
I have tried various options, I do not get the plot that I would expect. With the y parameter varying from 1.1 to 3.5, and with x varying from -pi to pi, I would expect a polar plot to show an annulus. This is based on my reading of the sentence “The X coordinate is mapped on the angle and the Y coordinate on the radius.” from the documentation of THistPainter, describing the “POL” option. When I plot it with just “colz”, I see the two blobs that I generated. When I plot it with “colz pol”, I only see one, and the regions start moving off the pad.
I tried using the “lego2” option along with “pol”, hoping that I could make a 3d plot, then rotate it until I am looking down from the top. However, the lego2 plot puts the innermost bin at radius 0, rather than at radius 1.1, as was specified in the plot.
{
TH2F* polar_hist = new TH2F("polar_hist","polar_hist",
32, -TMath::Pi(), TMath::Pi(),
24, 1.1, 3.5);
// Generate some data
for(int i=0; i<1e5; i++) {
double x = gRandom->Gaus(0.0, 0.3);
double y = gRandom->Gaus(1.2, 0.3);
double r = std::sqrt(x*x + y*y);
double theta = std::atan2(y,x);
polar_hist->Fill(theta, r);
x = gRandom->Gaus(0.0, 0.3);
y = gRandom->Gaus(-1.2, 0.3);
r = std::sqrt(x*x + y*y);
theta = std::atan2(y,x);
polar_hist->Fill(theta, r);
}
polar_hist->SetStats(0);
// Plot it 4 ways
TCanvas* can = new TCanvas;
can->Divide(2,2);
can->cd(1);
polar_hist->SetTitle("colz");
polar_hist->DrawCopy("colz");
can->cd(2);
polar_hist->SetTitle("colz pol");
polar_hist->DrawCopy("colz pol");
can->cd(3);
polar_hist->SetTitle("lego2 pol");
polar_hist->DrawCopy("lego2 pol");
can->cd(4);
polar_hist->SetTitle("lego2 pol colz");
polar_hist->DrawCopy("lego2 pol colz");
}
How should I go about making a polar plot?