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

**URL:** https://discourse.julialang.org/t/glmakie-polar-heatmap-millions-of-polygons/98470
**Category:** Performance
**Created:** [May 8, 2023, 1:10pm UTC](https://discourse.julialang.org/t/glmakie-polar-heatmap-millions-of-polygons/98470 "2023-05-08T13:10:22Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Ertyk](https://avatars.discourse-cdn.com/v4/letter/e/85f322/32.png) [@Ertyk](https://discourse.julialang.org/u/Ertyk)
#### Post date: [May 8, 2023, 1:10pm UTC](https://discourse.julialang.org/t/glmakie-polar-heatmap-millions-of-polygons/98470/1 "2023-05-08T13:10:22Z")

</div>

Hello,

I am trying to plot (a lot of) data in a live “polar heatmap”. A triangular visualization like below is ok.  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/5/b/5bcdbe4e72a509f1de728cf329d1beb870d9f1b6.png)

For now I have used polygons by modifying this example:  
[https://docs.makie.org/stable/examples/plotting\_functions/poly/](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?)

 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/d/ed06314702ddf4fe772837f7eb63907de317ad7f.png)

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

Code:

```julia
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.
    start_θ_rad = deg2rad(start_θ_deg)
    end_θ_rad = deg2rad(end_θ_deg)
    (start_θ_sin, start_θ_cos) = sincos(start_θ_rad)
    (end_θ_sin, end_θ_cos) = sincos(end_θ_rad)

    # 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()

```

---

<div class="post-metadata">

### Author: ![berjine](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/berjine/32/51764_2.png) [@berjine](https://discourse.julialang.org/u/berjine)
#### Post date: [February 20, 2024, 10:37am UTC](https://discourse.julialang.org/t/glmakie-polar-heatmap-millions-of-polygons/98470/2 "2024-02-20T10:37:20Z")

</div>

Not an exact solution to your problem but did you try using a standard heatmap with [InteractiveViz](https://github.com/org-arl/InteractiveViz.jl) ?  
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
