How do I set the max values for a plotly px.sunburst graph?

I am trying to show how much a student has completed from a set of challenges with a plotly sunburst graph. I want to have the ‘category’ maximum value be shown for each of them but only fill in the challenges that they’ve done. I was thinking of having the ones they did not do be greyed out. I have the max values for each of the challenges in the dataframe ‘challenge_count_df’ and the students work in the ‘student_df’:

import pandas as pd
import plotly.express as px

challenge_count_df = pd.DataFrame({'Challenge': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'],
                                  'Value' : ["5","5","10","15","5","10","5","10","15","10"],
                                  'Category' : ['linux','primer','windows','linux','linux','primer','windows','linux', 'linux', 'primer']})



student_df = pd.DataFrame({'Challenge': ['B', 'C', 'E', 'F', 'G', 'H', 'I'],
                                  'Value' : ["5","10","5","10","5","10","15"],
                                  'Category' : ['primer','windows','linux','primer','windows','linux', 'linux']})

As you can see, the student_df has some of the challenges missing. That’s because they didn’t answer them.

I know how to start a starburst like this:

fig = px.starburst(challenge_count_df, path=['Category','Challenge'],values='Value') 

Is there a way to overlap that with this?

fig = px.starburst(student_df, path=['Category','Challenge'],values='Value')

Or is there a way to build one based off the challenge count df and the color to be grey unless it’s in the student df?

I was thinking if I concatenated the two dataframes and renamed the student_values to ‘earned’ and maybe create a dictionary of the challenges that they didn’t answer to be the color grey then I could use the color_discrete_map function?


student_df = student_df.rename(columns={'Value':'Earned'})

combined_df = pd.concat([challenge_count_df,student_df]).fillna(0)

>>> combined_df
  Challenge Value Category Earned
0         A     5    linux      0
1         B     5   primer      0
2         C    10  windows      0
3         D    15    linux      0
4         E     5    linux      0
5         F    10   primer      0
6         G     5  windows      0
7         H    10    linux      0
8         I    15    linux      0
9         J    10   primer      0
0         B     0   primer      5
1         C     0  windows     10
2         E     0    linux      5
3         F     0   primer     10
4         G     0  windows      5
5         H     0    linux     10
6         I     0    linux     15


greyout_not_answered = dict()

for ch in combined_df[combined_df['Earned']==0]['Challenge']:
    greyout_not_answered[ch]='grey'

fig = px.starburst(challenge_count_df, path=['Category','Challenge'],values='Value',color_discrete_map=greyout_not_answered)

OH…forgot to change my examples…the challenges would be unique to each category.