Each layer has multiple color in sunburst chart

Hi,

There is 2 layer in the sunburst chart.

Category > Product

Currently, the color of the ‘product’ is same color with its ‘category’.

For example:

product = [‘Cup’, ‘Dress’, ‘Skirt’, ‘Pant’, ‘Knife’, ‘Plate’, ‘Bed’, ‘Table’]

category = [‘Kitchen’, ‘Wardrobe’, ‘Wardrobe’, ‘Wardrobe’,‘Kitchen’, ‘Kitchen’, ‘Bedroom’, ‘Bedroom’]

if the ‘Kitchen’ is red, when expand it to view the ‘product’, all the product under this category is red.

So, how can the ‘product’ has different color than the ‘category’?
such as ‘Cup’ is pink, ‘Knife’ is blue, ‘Plate’ is green

Hi @beginof,

Have you tried using the color and color_discrete_map attributes ?

You can change the desired colors by creating a color map dict:

color_discrete_map={'(?)':'black', 'Cup':'pink', 'Knife':'blue', 'Plate':'green'}
fig = px.sunburst(
    data,
    names='Product',
    parents='Category',
    values='value',
    color ='Product',
    color_discrete_map={'(?)':'black', 'Cup':'pink', 'Knife':'blue', 'Plate':'green'}
)
fig.show()

You can learn more about Sunburst :point_down:

Cheers!