# GLMakie - Polar heatmap/ millions of Polygons(?)

Hello,

I am trying to plot (a lot of) data in a live “polar heatmap”. A triangular visualization like below is ok.

For now I have used polygons by modifying this example:
https://docs.makie.org/stable/examples/plotting_functions/poly/

However my current solution is way to slow when I add millions of point.
I am not sure polygons like below code are the way to go, maybe someone have a tip on a more efficient way to draw something like this in GLMakie?
(overlapping triangles? something completly different?)

If anyone has suggestions it would be greatly appreciated! Thanks!

Code:

``````using GLMakie, GeometryBasics, BenchmarkTools, StaticArrays

function calc_polygons(start_θ_deg::Float64, end_θ_deg::Float64, amplitude::Vector{Float64})
# number of cells
n = length(amplitude)

# start point
p₀_start_az = Point2f(0, 0)
p₀_end_az = Point2f(0, 0)

# Pre-calculate sin and cos outside the loop to avoid redundant calculations.

# Pre-calculate start_θ_offset and end_θ_offset outside the loop to avoid redundant calculations.
start_θ_offset = Point2f(start_θ_cos, start_θ_sin)
end_θ_offset = Point2f(end_θ_cos, end_θ_sin)

polygons = [Polygon([
p₀_end_az   + (i-1) * end_θ_offset,
p₀_start_az + (i-1) * start_θ_offset,
p₀_start_az +  i    * start_θ_offset,
p₀_end_az   +  i    * end_θ_offset
]) for i in 1:n]

# convert amplitude vector to color vector
rgb_colors = [RGBf(amp,0,0) for amp in amplitude]

return (polygons, rgb_colors)
end

function main()
polygons, rgb_colors = calc_polygons(20., 30., rand(5));
poly(polygons, color = rgb_colors, overdraw = true)
end

main()
``````

Not an exact solution to your problem but did you try using a standard heatmap with InteractiveViz ?
You could rasterize your polygons into a big matrix and then plot it (using NaNs for the “void” pixels)
It depends on your computer of course but it can plot interactive heatmaps of several billion points