Black Lives Matter. Please consider donating to Black Girls Code today.

Make double donut plots (or donut plot with subgroups)

Is it possible to create double donut plots like this:

Donut plot with subgroups
img

Maybe with pandas dataframe?

Or what is the alternative plot for the purpose?

Thanks!

Didn’t see anyone from the dash community replies.

Is it possible to use plotly / python then?

Hi @yxuil,

There’s not a built-in way to do this, but you could build it out of two pie charts. Here’s a starting for you:

import plotly.graph_objs as go

labels = ['Oxygen','Hydrogen','Carbon_Dioxide','Nitrogen']
outer_values = [4500,2500,500]
inner_values = [500, 1000, 2000, 1000,
                 500, 1000, 1000,
                 200, 300]

common_props = dict(labels=labels,
                    values=values,)

trace1 = go.Pie(
    hole=0.5,
    sort=False,
    direction='clockwise',
    domain={'x': [0.15, 0.85], 'y': [0.15, 0.85]},
    values=inner_values,
    textinfo='label',
    textposition='inside',
    marker={'line': {'color': 'white', 'width': 1}}
)

trace2 = go.Pie(
    hole=0.7,
    sort=False,
    direction='clockwise',
    values=outer_values,
    labels=labels,
    textinfo='label',
    textposition='outside',
    marker={'colors': ['green', 'red', 'blue'],
            'line': {'color': 'white', 'width': 1}}
)

fig = go.FigureWidget(data=[trace1, trace2])
fig

You’ll probably want to play with the pie slice colors of the inner pie chart (trace1)

Hope that helps!
-Jon

This is excellent.

So the basic idea is to use “domain” parameter to place the inside pie chart on the top of outside pie chart, correct?

Yes, domain can be used to specify the size/location of the pie in normalized figure coordinates.