Polar Histogram

Hi! I wrote a little function to plot polar histograms using PolarAxis. I wonder if it’s a good idea to add something like this to makie?

using StatsBase
using Distributions
using CairoMakie

#set of angles in radian
angles = deg2rad.(rand(Normal(45,15), 100))
#bins limits in degrees
bins = [0, 15, 30, 45, 60, 75, 90]

function polarhist(angles, bins)

    bins = deg2rad.(bins)
    h = fit(Histogram, angles, bins)
    x = collect(h.edges[1])
    y = h.weights ./ sum(h.weights)
    f = Figure()
    ax = PolarAxis(f[1, 1], title="Polar Histogram")

    for i in eachindex(y)
        if y[i] > 0
            poly!(ax, [(0, 0), (y[i], x[i]), (y[i], x[i+1])], [1, 2, 3])
        end
    end
    return f
end

polarhist(angles, bins)
2 Likes