# Bug report: TH2::Draw with option "POL" wrongly transforms the coordinate for v6.36 and later

**URL:** <https://root-forum.cern.ch/t/bug-report-th2-draw-with-option-pol-wrongly-transforms-the-coordinate-for-v6-36-and-later/64949>\
**Category:** ROOT\
**Tags:** bug\
**Created:** [July 22, 2026, 7:30am UTC](https://root-forum.cern.ch/t/bug-report-th2-draw-with-option-pol-wrongly-transforms-the-coordinate-for-v6-36-and-later/64949 "2026-07-22T07:30:46Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![atsushi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/ed655f/32.png) [@atsushi](https://root-forum.cern.ch/u/atsushi)\
**Post date:** [July 22, 2026, 7:30am UTC](https://root-forum.cern.ch/t/bug-report-th2-draw-with-option-pol-wrongly-transforms-the-coordinate-for-v6-36-and-later/64949/1 "2026-07-22T07:30:50Z")

</div>

Dear experts,

I found a bug with the “pol” option of the TH2::Draw method for recent ROOT versions (6.36 and later). My guess is that something goes wrong with the mapping from the polar coordinate to the Cartesian coordinate.

The attached plots are produced by running a macro coded below in different ROOT versions:

```cpp
{
   auto c1 = new TCanvas("c1", "Polar Histogram", 600, 600);
   auto h = new TH2D("h", Form("Version %s", gROOT->GetVersion()), 100, -12, 12, 100, -12, 12);
   auto h2 = new TH2D("h2", "Polar Plot", 50, -1*TMath::Pi(), TMath::Pi(), 50, 5, 10);
   gRandom->SetSeed(10);
   for (int i = 0; i < 50000; i++) {
      double angle = gRandom->Uniform(-TMath::Pi(), TMath::Pi());
      double radius = gRandom->Uniform(5, 10);
      h2->Fill(angle, radius);
   }

   h->Draw("");
   h2->Draw("SAME COLZ POL");
}

```

Here, the region with 5 \< \sqrt{x^2+y^2} \< 10 in the histogram must be filled in the full -\pi\<\theta\<\pi range, as is the case for version 6.34. However, the attached plots produced by 6.36 and 6.38 are filled with the wrong radius only in the limited angle range.

All these plots were produced inside a container environment distributed on DockerHub, rootproject/root.  
Tested versions used to produce the plots are

- docker://rootproject/root:6.38.00-ubuntu25.10

- docker://rootproject/root:6.36.00-ubuntu25.04

- docker://rootproject/root:6.34.00-ubuntu24.10

 ![aa](https://root-forum.cern.ch/uploads/default/original/3X/2/2/22d4f369c9186fa6af79dad419b330125b0bab69.jpeg)

Best regards,  
Atsushi

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [July 22, 2026, 7:52am UTC](https://root-forum.cern.ch/t/bug-report-th2-draw-with-option-pol-wrongly-transforms-the-coordinate-for-v6-36-and-later/64949/2 "2026-07-22T07:52:47Z")

</div>

Welcome to the ROOT forum.  
I’ll check

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [July 22, 2026, 7:58am UTC](https://root-forum.cern.ch/t/bug-report-th2-draw-with-option-pol-wrongly-transforms-the-coordinate-for-v6-36-and-later/64949/3 "2026-07-22T07:58:59Z")

</div>

I see the same with ROOT master on Mac:

 ![Capture d’écran 2026-07-22 à 09.57.19](https://root-forum.cern.ch/uploads/default/original/3X/d/1/d1f8e6ce117c98d44427009e751adc9d3124817d.jpeg)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [July 22, 2026, 8:34am UTC](https://root-forum.cern.ch/t/bug-report-th2-draw-with-option-pol-wrongly-transforms-the-coordinate-for-v6-36-and-later/64949/4 "2026-07-22T08:34:37Z")

</div>

The change of behavior has been introduced by [this PR](https://github.com/root-project/root/commit/a3effce1a55af6650aee41fe2c5736ac8524d49f) from @linev. You can see the explanations in the PR commit’s comments. @linev is on holidays right now. He can comment when he will be back.

---

<div class="post-metadata">

**Author:** ![atsushi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/ed655f/32.png) [@atsushi](https://root-forum.cern.ch/u/atsushi)\
**Post date:** [July 22, 2026, 9:57am UTC](https://root-forum.cern.ch/t/bug-report-th2-draw-with-option-pol-wrongly-transforms-the-coordinate-for-v6-36-and-later/64949/5 "2026-07-22T09:57:04Z")

</div>

Thank you very much for the support.

I went through the source code committed there, trying to understand how it behaves.

I ran the following test macro (v6.36) and got the attached plot:

```cpp
{
   auto c1 = new TCanvas("c1", "Polar Histogram", 1200, 400);
   auto hBG = new TH2D("hBG", Form("Polar-adjusted BG pad"), 100, -TMath::Pi(), TMath::Pi(), 100, 0, 12);
   auto h = new TH2D("h", Form("BG pad in Cartesian"), 100, -12, 12, 100, -12, 12);
   auto h2 = new TH2D("h2", "Histo to be pol->Cartesian mapped", 50, -1*TMath::Pi(), TMath::Pi(), 10, 5, 10);
   gRandom->SetSeed(10);
   for (int i = 0; i < 50000; i++) {
      double angle = gRandom->Uniform(-TMath::Pi(), TMath::Pi());
      double radius = gRandom->Uniform(5, 10);
      h2->Fill(angle, radius);
   }

   c1->Divide(3,1);
   c1->cd(1);
   hBG->Draw("");
   h2->Draw("SAME COLZ POL");
   cout << Form("Uxmin: %.2f, Uxmax: %.2f, Uymin: %.2f, Uymax: %.2f", gPad->GetUxmin(), gPad->GetUxmax(), gPad->GetUymin(), gPad->GetUymax()) << endl;
   c1->cd(2);
   h2->Draw("COLZ POL");
   c1->cd(3);
   h->Draw();
   h2->Draw("SAME COLZ POL");
}

```

 ![aa](https://root-forum.cern.ch/uploads/default/original/3X/f/e/fe9218f6081f6c71fc8c584ddde69b58c39ba947.png)

My findings here are that the current “pol” option gives the actual polar coordinate of \theta = 2\pi \frac{x\_{pol} - x\_{BG}^{min}}{x\_{BG}^{max} - x\_{BG}^{min}} and r \propto y\_{pol} - y\_{BG}^{min} , where x,y\_{BG}^{min,max} are the xy-range of the background histogram objects (`hBG` for 1st pad, `h2` for 2nd pad, `h` for 3rd pad) and x,y\_{pol} are the xy-value at each bin of the histogram objects drawn with “pol” option. For example, in the 3rd plot, the angle range is limited because calculating something like \theta = \frac{3.14 + 12}{24} for x=3.14 bin of `h2` object.

Though the histogram itself in the first drawing is geometrically correct, the axis is taken from the background histogram object. Anyway, let’s wait for comments from the committer.

Atsushi

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [July 22, 2026, 10:59am UTC](https://root-forum.cern.ch/t/bug-report-th2-draw-with-option-pol-wrongly-transforms-the-coordinate-for-v6-36-and-later/64949/6 "2026-07-22T10:59:33Z")

</div>

> [@atsushi](#):
>
> Anyway, let’s wait for comments from the committer

Yes it is better @linev does the follow up.

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [July 23, 2026, 8:01am UTC](https://root-forum.cern.ch/t/bug-report-th2-draw-with-option-pol-wrongly-transforms-the-coordinate-for-v6-36-and-later/64949/7 "2026-07-23T08:01:51Z")

</div>

Hi Atsushi,

Yes, implementation of “POL” draw option was changed starting from ROOT 6.36.  
Previous implementation had many problems and didn’t work correctly in many use-cases.  
Just try to draw `hpxpy` histogram from `hsimple.C` example in polar coordinates. Especially interactive zooming was a real mess. Therefore I had doubts that such drawing can be used in productive work.

As you find out now polar coordinates recalculated from histogram X/Y ranges at the moment when painting performed. This let fix many existing problems but change produced plots. Main advantage of new approach - one do not need to create special axis histogram and can easily switch between different histogram draw options.

One can try to extend ROOT code and allow to use natural polar coordinates as histogram axes - but removing old problems. This can be done as “POLN” draw option. If you are interested - I can try to provide such option.

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![atsushi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/ed655f/32.png) [@atsushi](https://root-forum.cern.ch/u/atsushi)\
**Post date:** [July 23, 2026, 3:55pm UTC](https://root-forum.cern.ch/t/bug-report-th2-draw-with-option-pol-wrongly-transforms-the-coordinate-for-v6-36-and-later/64949/8 "2026-07-23T15:55:19Z")

</div>

Dear Sergey

Thank you for the reply. I saw the motivation for the modification.

> One can try to extend ROOT code and allow to use natural polar coordinates as histogram axes - but removing old problems. This can be done as “POLN” draw option. If you are interested - I can try to provide such option.

Yes, I would like to have such an option. With the current implementation, the lower and upper boundaries of the x-axis are bound to \theta = 0, 360^\circ, as far as I understand. However, in my use cases, I fill histograms with polar coordinate (e.g. describing hit maps on radially designed detectors) with the x-range of the histogram being [-\frac{1}{2}\pi, \frac{3}{2}\pi] for example, not always [0, 2\pi] . Therefore, I would like to request some tools to rotate the Cartesian-mapped histogram.

Thank you for the support,  
Atsushi

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [July 24, 2026, 3:16pm UTC](https://root-forum.cern.ch/t/bug-report-th2-draw-with-option-pol-wrongly-transforms-the-coordinate-for-v6-36-and-later/64949/9 "2026-07-24T15:16:45Z")

</div>

Dear Atsushi,

I create PR which implements new “POLN” and “POLF” draw options.

> <https://github.com/root-project/root/pull/22913>
>
> Since ROOT 6.36 implementation of "POL" draw option was changed. Angle and radi…us range automatically scaled to visible histogram range filling full 2\*Pi angle and \[0..max\] radius range. This let display TH2 in polar coordinates for any provided range settings, but produced plots are not intuitive.
> 
> Therefore two new options for polar coordinates were introduced.
> 
> "POLF" - fixed polar coordinates. In such case full histogram X range mapped to -PI .. +Pi. And Y axis mapped to radius. In case of histogram zooming angle and radius of each bin remains the same (therefore name "fixed"), just number of displayed bins are reduced.
> 
> "POLN" - natural polar coordinates. In this case X axis directly represents angle value in radians (therefore name "natural") and Y axis is just radius. Such functionality was requested in https://root-forum.cern.ch/t/64949/
> 
> Also "POL" was modified. Now X range mapped to \[-180 .. 180) range making more intuitive presentation when central histogram X region displayed near angle 0 on the right side of polar plot.

Can you try it to check if it works as you expected.

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![atsushi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/ed655f/32.png) [@atsushi](https://root-forum.cern.ch/u/atsushi)\
**Post date:** [July 26, 2026, 10:08am UTC](https://root-forum.cern.ch/t/bug-report-th2-draw-with-option-pol-wrongly-transforms-the-coordinate-for-v6-36-and-later/64949/10 "2026-07-26T10:08:46Z")

</div>

Dear Sergey,

Thank you for the update. I tried the new “POLN” option, but I am afraid that the mapping to the Cartesian coordinate is not rigid in some cases, even without zooming.

In the code below, I provide two typical cases (in the case switch part).

```auto
{
   Double_t rRange[2], xRange[2], yRange[2];
   Int_t caseID = 1;
   switch (caseID) {
   case 0:
      rRange[0] = 5;
      rRange[1] = 10;
      xRange[0] = -12;
      xRange[1] = 12;
      yRange[0] = -20;
      yRange[1] = 20;
      break;
   case 1:
      rRange[0] = 1;
      rRange[1] = 2;
      xRange[0] = -3;
      xRange[1] = 3;
      yRange[0] = -3;
      yRange[1] = 3;
      break;
   }

   TString polOpt = "POLN";
   auto c1 = new TCanvas("c1", "Polar Histogram", 600, 600);
   auto hBG = new TH2D("hBG", Form("Version %s, %s", gROOT->GetVersion(), polOpt.Data()), 100, xRange[0], xRange[1], 100, yRange[0], yRange[1]);
   auto hPol = new TH2D("hPol", "Polar Plot", 50, -0.5*TMath::Pi(), 1.5*TMath::Pi(), 50, rRange[0], rRange[1]);
   gRandom->SetSeed(10);
   for (int i = 0; i < 50000; i++) {
      double angle = gRandom->Uniform(-0.25*TMath::Pi(), 1.1*TMath::Pi());
      double radius = gRandom->Uniform(rRange[0], rRange[1]);
      hPol->Fill(angle, radius);
   }

   hBG->Draw("");
   hPol->Draw(Form("SAME COLZ %s", polOpt.Data()));
}

```

The attached plots show the result of this macro.

- case = 0: Even though the radius range is smaller than the x and y-ranges of `hBG`, the “POLN” plots extend to the full range of hBG.
- case = 1: When the x-range of `hBG` is smaller than \pi, the \theta range gets affected.

In both of these plots, i would expect to see plots that are produced by the 6.34 version, which perfectly matches the r\cos\theta, r\sin\theta to the `hBG` axes.

I believe that the consistency of the coordinate definition is essential when “POLN SAME” option is used, for example when radially designed detectors are overlaid with other detector components or tracks. May I ask you to design the “POLN” option accordingly?

Thank you,  
Atsushi

 ![スクリーンショット 2026-07-26 11.15.29](https://root-forum.cern.ch/uploads/default/original/3X/c/7/c720c14512d99e889389b61eccb6577de3a11e70.jpeg)

 ![スクリーンショット 2026-07-26 11.13.40](https://root-forum.cern.ch/uploads/default/original/3X/3/6/3605cd293f1ed003060928f74bbc87bc9b381035.jpeg)

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [July 27, 2026, 9:17am UTC](https://root-forum.cern.ch/t/bug-report-th2-draw-with-option-pol-wrongly-transforms-the-coordinate-for-v6-36-and-later/64949/11 "2026-07-27T09:17:55Z")

</div>

Dear Atsushi,

I see that you prefer to use special histogram to define axes ranges.  
As a result, when `caseID == 1` your axes histogram has smaller angle range than actual polar histogram and therefore not all bins for the histogram will be displayed. Also bin content (Z scale) is drawn absolutely incorrectly - you need to define minimum/maximum in your axes histogram.

I change PR to correctly use axis histogram ranges when it provided. Produced output for both cases:

 ![case0same](https://root-forum.cern.ch/uploads/default/original/3X/0/5/0547f6282b4b8494e49914abb5b2d7fad83aee62.png)  
 ![case1same](https://root-forum.cern.ch/uploads/default/original/3X/0/3/03a7e4c5f9b345070466bee114e331556713486b.png)

I also adjust code when same histogram drawn without axis. In such case Z scale works normally and angle/radius ranges defined by histogram itself.

 ![case0](https://root-forum.cern.ch/uploads/default/original/3X/7/a/7a3bb060a6eeeccc28274c0e0154c723f6d0653f.png)  
 ![case1](https://root-forum.cern.ch/uploads/default/original/3X/7/1/713357420186db43e355cf7090969a3cbcd48114.png)

Please check if modified code fit better to your needs.

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![atsushi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/ed655f/32.png) [@atsushi](https://root-forum.cern.ch/u/atsushi)\
**Post date:** [July 27, 2026, 1:01pm UTC](https://root-forum.cern.ch/t/bug-report-th2-draw-with-option-pol-wrongly-transforms-the-coordinate-for-v6-36-and-later/64949/12 "2026-07-27T13:01:46Z")

</div>

Dear Sergey,

Thank you. Now the “POLN” seems to be working as I expect, also in my environment.

Best regards,  
Atsushi

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [August 10, 2026, 1:02pm UTC](https://root-forum.cern.ch/t/bug-report-th2-draw-with-option-pol-wrongly-transforms-the-coordinate-for-v6-36-and-later/64949/13 "2026-08-10T13:02:01Z")

</div>

Closed on August 10, 2026, 1:02pm UTC

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