# Nested Pie charts

**URL:** <https://community.plotly.com/t/nested-pie-charts/24011>\
**Category:** 📊 Plotly Python\
**Created:** [May 30, 2019, 8:18pm UTC](https://community.plotly.com/t/nested-pie-charts/24011 "2019-05-30T20:18:18Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhurtado](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@jhurtado](https://community.plotly.com/u/jhurtado)\
**Post date:** [May 30, 2019, 8:18pm UTC](https://community.plotly.com/t/nested-pie-charts/24011/1 "2019-05-30T20:18:18Z")

</div>

![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/5/59c30b6879058e6f121dfc00223121774aa6f253.jpeg)

I took the following picture from this post. [Linking traces in nested pie chart (for legend toggle functionality)](https://community.plotly.com/t/linking-traces-in-nested-pie-chart-for-legend-toggle-functionality/15433)

I have data that would recreate this nested pie chart however I cant seem to find the way to connect data from the outer donut with the inner donut so it will show the outer donut as part of the inner donut percentage.

Any help or guidance would be appreciated.

Here’s a simplified code that recreates the following nested pie chart (also taken from the post

 ![newplot%20(31)](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/5/5e98ee6227ea65dd630a0fb8aaefe8bec4ba5396.png) )

import plotly.graph\_objs as go

data = [# Portfolio (inner donut)  
go.Pie(values=[20,40],  
labels=[‘Reds’,‘Blues’],  
domain={‘x’:[0.2,0.8], ‘y’:[0.1,0.9]},  
hole=0.5,  
direction=‘clockwise’,  
sort=False,  
marker={‘colors’:[’#CB4335’,’#2E86C1’]}),  
# Individual components (outer donut)  
go.Pie(values=[5,15,30,10],  
labels=[‘Medium Red’,‘Light Red’,‘Medium Blue’,‘Light Blue’],  
domain={‘x’:[0.1,0.9], ‘y’:[0,1]},  
hole=0.75,  
direction=‘clockwise’,  
sort=False,  
marker={‘colors’:[’#EC7063’,’#F1948A’,’#5DADE2’,’#85C1E9’]},  
showlegend=False)]

fig = go.Figure(data=data, layout={‘title’:‘Nested Pie Chart’})

plotly.offline.iplot(fig)

---

<div class="post-metadata">

**Author:** ![jmmease](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jmmease/32/3706_2.png) [@jmmease](https://community.plotly.com/u/jmmease)\
**Post date:** [June 1, 2019, 11:24am UTC](https://community.plotly.com/t/nested-pie-charts/24011/2 "2019-06-01T11:24:22Z")

</div>

Hi @jhurtado,

I’d recommend using the new `sunburst` trace type for this rather than a collection of `pie` traces. See [https://plot.ly/python/sunburst-charts/](https://plot.ly/python/sunburst-charts/) for info on the sunburst trace type.

Hope that helps!

-Jon

---

<div class="post-metadata">

**Author:** ![jhurtado](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@jhurtado](https://community.plotly.com/u/jhurtado)\
**Post date:** [June 5, 2019, 9:26pm UTC](https://community.plotly.com/t/nested-pie-charts/24011/3 "2019-06-05T21:26:46Z")

</div>

Hi John,

Thank you so much for your help. In my opinion it did work but I’m missing one last thing.

 ![newplot%20(32)](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/5/55108d4c13da90a5b714189a2b30c18b975e8598.png)

I’m trying to find the way to show as proportions which it kind of does but I was just wondering If I can control  
how these proportions are shown in the plot. (e.g No whitespaces in between each other and that if I have percentages it’s shown ‘areawise’ reflected in the chart) (I hope that makes sense).

Thanks again,

---

<div class="post-metadata">

**Author:** ![chriddyp](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/chriddyp/32/16855_2.png) [@chriddyp](https://community.plotly.com/u/chriddyp)\
**Post date:** [June 5, 2019, 10:00pm UTC](https://community.plotly.com/t/nested-pie-charts/24011/4 "2019-06-05T22:00:31Z")

</div>

Try `branchvalues='total'`:

```auto
trace = go.Sunburst(
    labels=["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
    parents=["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve"],
    values=[65, 14, 12, 10, 2, 6, 6, 4, 4],
    branchvalues="total",
    outsidetextfont = {"size": 20, "color": "#377eb8"},
    marker = {"line": {"width": 2}},
)

layout = go.Layout(
    margin = go.layout.Margin(t=0, l=0, r=0, b=0)
)

figure = {
    'data': [trace],
    'layout': layout
}

```

![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/1/147aca5415dff99f2ec6f16f9518dd8d5669f7ed.png)

---

<div class="post-metadata">

**Author:** ![jhurtado](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@jhurtado](https://community.plotly.com/u/jhurtado)\
**Post date:** [June 6, 2019, 4:11pm UTC](https://community.plotly.com/t/nested-pie-charts/24011/5 "2019-06-06T16:11:23Z")

</div>

Hi @chriddyp,

First of all, thanks for your help! I’m trying to add that argument but it’s not working for me. I only got a white screen.

```
trace = go.Sunburst(
 
  values = [36964.92, 36964.92, 36964.92, '35H', '37H', '39H', '35H', '37H', '39H', '35H', '37H', '39H'],
  
  labels = ['35H', '37H', '39H', 'ballooning_%35H', 'ballooning_%37H', 'ballooning_%39H', 'normal_propagation_%35H', 'normal_propagation_%37H', 'normal_propagation_%39H', 'unknown_%35H', 'unknown_%37H', 'unknown_%39H'],
    
  parents = [17075.199999999997, 11883.349999999999, 8006.366666666666, 903.8166666666666, 756.5333333333333, 682.0166666666667, 4454.0, 3163.6499999999996, 2311.3166666666666, 11717.383333333335, 7963.166666666666, 5013.033333333333], 
  
branchvalues='total',
  outsidetextfont={"size": 20, "color": "#377eb8"},
  leaf={"opacity": 0.4},
  marker={"line": {"width": 2}},
    
    
)

layout = go.Layout(
    margin = go.layout.Margin(t=0, l=0, r=0, b=0)
                
    
)

fig = go.Figure([trace], layout)

plotly.offline.iplot(fig)

```

I made sure that every branch value not was higher than the total which may create the error. May it be the way set up branches?

any help would be appreciate it.

---

<div class="post-metadata">

**Author:** ![jmmease](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jmmease/32/3706_2.png) [@jmmease](https://community.plotly.com/u/jmmease)\
**Post date:** [June 10, 2019, 10:40am UTC](https://community.plotly.com/t/nested-pie-charts/24011/6 "2019-06-10T10:40:32Z")

</div>

Hi @jhurtado,

I think there may be a problem with your specification of the `parents` array. The elements of `parents` need to match elements of `values`, but that doesn’t seem to be the case in this example.

Hope that helps,  
-Jon

---

<div class="post-metadata">

**Author:** ![jhurtado](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@jhurtado](https://community.plotly.com/u/jhurtado)\
**Post date:** [June 10, 2019, 3:45pm UTC](https://community.plotly.com/t/nested-pie-charts/24011/7 "2019-06-10T15:45:52Z")

</div>

Thanks Jon,

I really appreciate your help and you were right it was something about the configuration on the parents array designation.

 ![newplot%20(33)](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/1/1ef07040049d4f827948f5383fe62eee4c568a87.png)

I was able to finish one part of it and now I’m working on the other two.

Thanks for your help and also @chriddyp

Best,

---

<div class="post-metadata">

**Author:** ![nandan-nayak](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/nandan-nayak/32/7291_2.png) [@nandan-nayak](https://community.plotly.com/u/nandan-nayak)\
**Post date:** [July 13, 2019, 4:29pm UTC](https://community.plotly.com/t/nested-pie-charts/24011/8 "2019-07-13T16:29:07Z")

</div>

Large number of slices is not working for sunburst charts even if parents and value array matches

> [@Large number of slices for sunburst chart is not working](https://community.plotly.com/t/large-number-of-slices-for-sunburst-chart-is-not-working/25765):
>
> (upload://zBgtBbnrLpbQdlzMZcHeFB1jEkv.png) Large number of slices for sunburst charts which is working in your case [https://plot.ly/python/sunburst-charts/](https://plot.ly/python/sunburst-charts/) is not working in my case, it just appears a blank white screen without any charts. length of labels , ids , parents is 74 ( with repetition), but it works fine (chart appears properly) if the length of the labels,ids,parents is 35 (with repetition). ?? import plotly import plotly.graph\_objs as go values=[14439.6, 650.0, 202.0, 242.0,…

---

<div class="post-metadata">

**Author:** ![ramya19it](https://avatars.discourse-cdn.com/v4/letter/r/85f322/32.png) [@ramya19it](https://community.plotly.com/u/ramya19it)\
**Post date:** [November 1, 2019, 5:08pm UTC](https://community.plotly.com/t/nested-pie-charts/24011/9 "2019-11-01T17:08:06Z")

</div>

I am working on the sunburst charts too. I also want to display the percentage values with respect to parent for the leaves. Is there a way to include percentage along with the labels on the sunburst chart?

---

<div class="post-metadata">

**Author:** ![daniel.legge](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/daniel.legge/32/27450_2.png) [@daniel.legge](https://community.plotly.com/u/daniel.legge)\
**Post date:** [March 24, 2024, 12:03am UTC](https://community.plotly.com/t/nested-pie-charts/24011/10 "2024-03-24T00:03:37Z")

</div>

This is exactly what I needed to complete a complex visualization. The key piece I was missing was the domain attribute on my inner sunburst chart. 👍
