GRUtils.jl icon indicating copy to clipboard operation
GRUtils.jl copied to clipboard

Differences with GR polar plots

Open heliosdrm opened this issue 5 years ago • 3 comments

Take this code:

angles = LinRange(0, 30, 100)
radii = LinRange(-2, 4, 100)
polar(angles, radii)

This is the output of GR: gr_polarplot

But GRUtils makes this: grutils_polarplot_1

There are two differences:

  • Most noticeably, the radial axis in GRUtils has always its center in zero. That's the reason why the line starts on the left side of the horizontal axis, instead of the center (it starts with negative radius) and then loops around the center (when the radius approaches zero).
  • Also, since the API of the function assumes that angles are given in radians, the angle labels are given as 0, π/4, π/2, etc., instead of 0, 45º, 90º..., such that the values shown are consistent with the input.

If wanted, the angles can be represented in degress, with the keyword argument radians=false - but in that case the input is also assumed to be in degrees:

polar(angles, radii, radians=false) # only in GRUtils

grutils_polarplot_2

I think that fixing the center to zero is more correct than the current approach of GR. Regarding the default angle units I'm not that much convinced. Labels in degrees look more familiar; but in that case I'd suggest also assume that the input is in degrees as well.

heliosdrm avatar Feb 05 '20 19:02 heliosdrm

There are further differences in the case of polar histograms:

  • By default, the bars (angular sectors) are distributed according to the actual range of the bins; you must use the keyword argument fullcircle=true to stretch them and fit the full circle (the default behavior of GR's polarhistogram)

For instance:

using GRUtils
data = π/2*rand(1000)
polarhistogram(data, nbins=20)

ph1

While in GR it would look rather like this:

polarhistogram(data, nbins=20, fullcircle=true)

ph2

  • The other difference (more subtle) is that I am drawing the bars as filled arcs, which (in my opinion) look nicer than the original triangles, specially if they cover a wide angle.

heliosdrm avatar Feb 07 '20 18:02 heliosdrm

Thanks a lot - I changed the polar transformations in GR#master. You are right, things should be compatible with MATLAB.

jheinen avatar Mar 01 '20 12:03 jheinen

What's your opinion on the scale and labelling of angles? In MATLAB, angles of polar plots are given in radians, but the radial grid shows them in degrees. GR also does it like that. Here I was experimenting with showing the grid in a way that is consistent with the scale, but I'm not sure about it.

heliosdrm avatar Mar 04 '20 21:03 heliosdrm