Problems with plotly express sunburst charts

Hi,

So i’m trying to learn how to build sunburst charts but have run into a few problems/questions. If anyone could answer one/all of them I would really appreciate it! Here is a list I made below:

Question1

How does the sunburst decide what colors to make things? When the colors are mapped using “color_discrete_map” as well as “color” I read in the documentation that the parent wedge takes the first color it receives, elsewhere it says that sometimes it merges the colors together to create a new color. So which is it?

e.g

Why is it that the Male/Female, Thursday, and Friday are black when there is nothing on the outside rim that is black?

Question 2

I’m not sure why but my legend doesn’t show up when I run the sunburst chart using color to measure a variable. There should be a legend which shows the Victim’s Age on a scale with darker indicating an older age and lighter indicating a younger age. I’ve tried including “fig.update_layout(showlegend=True)” at the end of my code but that hasn’t done anything.

fig2 = px.sunburst(sunburst_df1,
                  path = ['Unarmed','State','Victim\'s race'],
                  color = 'Victim\'s age',
                  color_continuous_scale=px.colors.sequential.BuGn, #See color scale from documentation. Use continuous when using color as a metric of another column.
                  #In this case measuring age with colors
                  #https://plotly.com/python/builtin-colorscales/
                  range_color=[10,100], #When you start and stop recording/measuring
                  maxdepth= -1,
                  template= 'ggplot2'
                  )

Produces this chart:

I am missing the legend which is produced here on the right:

Question 3

I am unable to remove the “id” and “labels” on hover_data. Python gives me an error when I run this:

hover_data={"Victim's gender": False, "id":False, "labels":False}

It is telling me that it is expecting “id” and “labels” as a column in my dataframe. When the person I am copying ran the same code it worked for them, so I’m not sure what is going on. I have plotly 4.14.3 and plotly express 0.4.1.

Here is the full code I wrote for the sunburst:

ChallengeFig = px.sunburst(
    sunburst_df2,
    path = ['State','Unarmed',"Victim's gender"],
    color = "Victim's gender",
    color_discrete_sequence=px.colors.qualitative.Pastel,
    color_discrete_map= {'Male': 'blue', 'Female':'pink'},
    #*Note for the inner wedges that aren't mapped "the first color of the discrete color sequence is used in it's children. Sometimes it also mixes colors. Honestly no clue"
    hover_data={"Victim's gender": False, "id":False, "labels":False},
    template='ggplot2'
)

Error:

ValueError: Value of 'hover_data_1' is not the name of a column in 'data_frame'

Thank you to anyone who can help me!! :slight_smile: