Hello to everyone !
I’m working on a sunburst with plotly. You can see the code and plot below. I used a discret color_map to set the color to the plot. The color_mapping contains the color of the parents (Vitamin, Mineral, Storable, Not Storable) however plotly decide to use the default color instead of the color_mapping. I’m afraid there is no solution because of the structure of the df.
# Step 4: Create the sunburst chart
# Create the sunburst chart with updated hover data
fig = px.sunburst(
df_micronutrients,
path = ['N0','N1','N2'],
values='Intake',
color='Micronutrient_name',
color_discrete_map=color_mapping, # Use direct mapping for colors
custom_data=['Intake', 'AS', 'LSS', 'Intake_to_AS_Ratio'] # Include the ratio in the hover data
)
# Customize hover template to show the intake to AS ratio
fig.update_traces(
hovertemplate="<b>%{label}</b><br>Intake: %{customdata[0]}<br>AS: %{customdata[1]}<br>LSS: %{customdata[2]}<br>Intake/AS Ratio: %{customdata[3]}"
)
# Customize the figure's layout
fig.update_layout(
margin=dict(t=0, l=0, r=0, b=0),
paper_bgcolor='white',
font=dict(family='Arial, sans-serif', size=12, color='black')
)
# Show the figure
fig.show()