Labels in pie charts in Makie

Hi there!

I was wondering how to put labels on a pie chart in Makie. Like in the example shown on the page.

using CairoMakie


data   = [36, 12, 68, 5, 42, 27]
colors = [:yellow, :orange, :red, :blue, :purple, :green]

f, ax, plt = pie(data,
                 color = colors,
                 radius = 4,
                 inner_radius = 2,
                 strokecolor = :white,
                 strokewidth = 5,
                 axis = (autolimitaspect = 1, )
                )

f

How could I for example use to colors as a label, all the things I tried did not work out…

Thanks!

what about doing:

using GLMakie
data   = [36, 12, 68, 5, 42, 27]
colors = [:yellow, :orange, :red, :blue, :purple, :green]
nc = length(colors)
nδ = 1/nc

f, ax, plt = pie(data,
                 color = colors,
                 radius = 4,
                 inner_radius = 2,
                 strokecolor = :white,
                 strokewidth = 5,
                 axis = (autolimitaspect = 1, )
                )
cbar = Colorbar(f[1,2], colormap = cgrad(colors, categorical = true))
cbar.ticks = (range(0+nδ/2, 1-nδ/2, nc), string.(colors))
f

1 Like

Yes good idea, this works! Thanks!
But still it would be better if one could label die pieces immediately.

I also struggled with this. I ended up creating a dummy scatter plot object that matched the data points for the pie chart.

let 
    data   = [36, 12, 68, 5, 42, 27]
    colors = [:yellow, :orange, :red, :blue, :purple, :green]

    f, ax, plt = pie(data,
                    color = colors,
                    radius = 4,
                    inner_radius = 2,
                    strokecolor = :white,
                    strokewidth = 5,
                    axis = (autolimitaspect = 1, )
                    )

    for x in 1:length(data)
        scatter!(ax, zeros(10), zeros(10), color = colors[x], label=string(colors[x]))
    end
    scatter!(ax, zeros(10), zeros(10), color = :white)
    axislegend()
    f
end

Would such an annotation be good enough?