How to use color_discrete_sequence in sunburst subplot instead of using default color?

I’ve created each individual sunburst chart (sb1, sb2, sb3) with “color_discrete_sequence=px.colors.qualitative.Pastel” but when I run the code below at the end to turn them into a subplot, it just returns Plotly’s default color.

fig = make_subplots(rows=1, cols=3, 
                    specs=[
    [{"type": "sunburst"}, {"type": "sunburst"}, {"type": "sunburst"}]
])

fig.add_trace(sb1.data[0], row=1, col=1)
fig.add_trace(sb2.data[0], row=1, col=2)
fig.add_trace(sb3.data[0], row=1, col=3)
fig.show()

Is there somewhere else in the code I need to add “color_discrete_sequence=px.colors.qualitative.Pastel” in order for it to work? Also, how would I give each chart it’s own color_discrete_sequence? Thanks!

1 Like

@rtb

To get help you must give more information on your code. I give an example of sunburst subplots where each one has been defined initially via px.sunburst:

fig = make_subplots(rows=1, cols=2, 
                    specs=[ [{"type": "sunburst"}, {"type": "sunburst"}])

df = px.data.tips()
figaux = px.sunburst(df, path=['sex', 'day', 'time'], values='total_bill', color='time', 
                      color_discrete_sequence=px.colors.qualitative.Pastel)
fig.add_trace(figaux.data[0], row=1, col=1)
figaux = px.sunburst(df, path=['sex', 'day', 'time'], values='total_bill', color='time',
                  color_discrete_map={'(?)':'black', 'Lunch':'gold', 'Dinner':'darkblue'})
fig.add_trace(figaux.data[0], row=1, col=2)
fig.update_layout(width=700, height=400)

1 Like

This is great! Thank you! I was defining each px.sunburst before “fig = make_subplots” but looks like your way works! I also figured out that passing:

fig.update_layout(sunburstcolorway = px.colors.qualitative.Pastel)

at the end of the code was able to color each individual subplot but I will keep your example for future reference.

1 Like