add labels to a pie chart in Makie.jl

211 views Asked by At

I would like to add a label for each color in a Makie.jl-pie chart, e.g.,

data   = [0.63, 0.15, 0.11, 0.11, 0.01]
colors = [:red, :yellow, :grey, :blue, :green]
f, ax, plt = CairoMakie.pie(data, color=colors, axis = (autolimitaspect = 1, ), label="A,B,C,D,E")
Legend(f[1,2], ax)
display(f)

but not one label for the whole pie chart but for each color separately. The label-attribute doesn't seem to accept vectors and labels doesn't exist.

1

There are 1 answers

0
AboAmmar On

You can try adding the labels using the text key in a loop like this.

using CairoMakie

data = [0.63, 0.15, 0.11, 0.11, 0.01]
colors = [:red, :yellow, :grey, :blue, :green]
labels = ["A", "B", "C", "D", "E"]

f, ax, plt = CairoMakie.pie(data, color=colors, axis=(autolimitaspect=1,))
for (i, c) in enumerate(colors)
    θ = sum(data[1:i-1]) + data[i]/2
    r = 0.5
    x = r*cos(θ)
    y = r*sin(θ)
    text(x, y, text=labels[i], halign=:center, valign=:center, color=:black)
end
display(f)