# Percentages in pie plot

**URL:** https://discourse.julialang.org/t/percentages-in-pie-plot/82366
**Category:** General Usage
**Tags:** plotting
**Created:** [June 7, 2022, 10:33am UTC](https://discourse.julialang.org/t/percentages-in-pie-plot/82366 "2022-06-07T10:33:37Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)
#### Post date: [June 7, 2022, 10:33am UTC](https://discourse.julialang.org/t/percentages-in-pie-plot/82366/1 "2022-06-07T10:33:37Z")

</div>

How to show percentages also in pie plot ? I want to show percentages of “Will churn” and “Will not churn”.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/2/921d007feb394b40a09fdeda68d5d41539f627cb.png)

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [June 7, 2022, 11:59am UTC](https://discourse.julialang.org/t/percentages-in-pie-plot/82366/2 "2022-06-07T11:59:02Z")

</div>

I feel that you’ve been pointed to this before, but as a reminder, please read:

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

and follow the advice therein. In particular:

1. Post actual code, not screenshots
2. Make **M** inimum **W** orking **E** xamples for your questions which allow others to run the code you’re trying to run. This includes any packages used.

The second part is particularly important when asking about plotting packages - there are plenty of different options available, and answers are generally useful for one specific package only so asking a generic plotting question without specifying a package isn’t very useful.

---

<div class="post-metadata">

### Author: ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)
#### Post date: [June 7, 2022, 12:30pm UTC](https://discourse.julialang.org/t/percentages-in-pie-plot/82366/3 "2022-06-07T12:30:00Z")

</div>

i am using plots.jl and gr backend for plotting. code is lengthy so i haven’t putted it. you can tell me resources to read so that i could also add percentages in pie plot. i wasn’t able to find examples on internet to get percentqages in pie plot.

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [June 7, 2022, 12:41pm UTC](https://discourse.julialang.org/t/percentages-in-pie-plot/82366/4 "2022-06-07T12:41:48Z")

</div>

That’s why it’s called an **M** WE - the point is to only post code which illustrates your specific problem. In your case an MWE is:

```julia
julia> using Plots

julia> pie(["Y", "N"], [25, 75])

```

and one answer to annotating the plot is:

```julia
julia> annotate!([-0.25, 0.25], [-0.25, 0.25], ["75%", "25%"])

```

---

<div class="post-metadata">

### Author: ![Pol\_del\_Aguila\_Pla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pol_del_aguila_pla/32/207687_2.png) [@Pol\_del\_Aguila\_Pla](https://discourse.julialang.org/u/Pol_del_Aguila_Pla)
#### Post date: [March 12, 2024, 10:39am UTC](https://discourse.julialang.org/t/percentages-in-pie-plot/82366/5 "2024-03-12T10:39:27Z")

</div>

Sorry to revive the topic, but there seems to be no documentation available to seriously do this. The reply is also a bit disingenuous ☹

An ack of the (apparently) limited capabilities for these things would have been nice.

A new MWE

```julia
data = rand(1:10,100)
ps = [sum(data.==val)/100 for val in 1:10]
pie(["$(v)" for v in 1:10], ps)

```

How do we state the percentages here, so that they are properly located? That’s the question most people ending up here have, I think.

 ![Screenshot from 2024-03-12 11-39-08](https://global.discourse-cdn.com/julialang/original/3X/8/5/852899b31495aeb40d187d763fbd34f36c8ab729.png)

---

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [March 12, 2024, 11:41am UTC](https://discourse.julialang.org/t/percentages-in-pie-plot/82366/6 "2024-03-12T11:41:38Z")

</div>

> [@Pol\_del\_Aguila\_Pla](#):
>
> An ack of the (apparently) limited capabilities for these things would have been nice.

I hereby acknowledge that Plots.jl and Makie.jl need more work, it’s currently not easy to make pie plots with them that follow best practices.

There are other options though, like the one given [here](https://discourse.julialang.org/t/pie-charts/34707/3):

```julia
using PyPlot
pie([15,15,30,60], explode=[0,0.3,0,0], labels=["A","B","C","D"],
    autopct="%1.1f%%", shadow=true, startangle=90)

```

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

---

<div class="post-metadata">

### Author: ![Pol\_del\_Aguila\_Pla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pol_del_aguila_pla/32/207687_2.png) [@Pol\_del\_Aguila\_Pla](https://discourse.julialang.org/u/Pol_del_Aguila_Pla)
#### Post date: [March 12, 2024, 12:12pm UTC](https://discourse.julialang.org/t/percentages-in-pie-plot/82366/7 "2024-03-12T12:12:51Z")

</div>

Thank you so much 🙂

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [March 12, 2024, 2:30pm UTC](https://discourse.julialang.org/t/percentages-in-pie-plot/82366/8 "2024-03-12T14:30:08Z")

</div>

> [@sijo](#):
>
> it’s currently not easy to make pie plots with them that follow best practices

I think pie plots themselves are regarded as not being best practice, so I guess that’s why interest in them has been relatively low. The niche features take longer to implement because no one wants to do it 🙂

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [March 12, 2024, 2:41pm UTC](https://discourse.julialang.org/t/percentages-in-pie-plot/82366/9 "2024-03-12T14:41:54Z")

</div>

With Plots.jl, for the record:

```julia
using Plots, Printf

data = [125, 125, 250, 500]
labels = ["A", "B", "C", "D"]
tot = sum(data)
datapct = [@sprintf("%.1f%%", x/tot*100) for x in data]

θ = (cumsum(data) - data/2) .* 360/sum(data)
scθ = sincosd.(θ)

p = pie(labels, data)
for (s, sci) in zip(datapct, scθ)
    annotate!(0.6*sci[2], 0.6*sci[1], text(s, 9, :black))
end
p

```

 ![Plots_pie_plot_with_percentages](https://global.discourse-cdn.com/julialang/original/3X/1/2/12d6cf1a1e93f38f082291e14fc872dbed24248b.png)

---

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [March 12, 2024, 3:03pm UTC](https://discourse.julialang.org/t/percentages-in-pie-plot/82366/10 "2024-03-12T15:03:02Z")

</div>

> [@jules](#):
>
> I think pie plots themselves are regarded as not being best practice, so I guess that’s why interest in them has been relatively low. The niche features take longer to implement because no one wants to do it 🙂

Totally! The last time I remember “needing” a pie chart was to show in a course how to do it with Makie. I thought of making a PR but that was not enough motivation. I’m waiting for a real use case.

I think there are cases where it’s good practice though: when you have just a few values and want to show for each what is the fraction of the total. See [Have I Resolved the Pie Chart Debate?](https://nightingaledvs.com/have-i-resolved-the-pie-chart-debate/)
