@@ -106,7 +106,8 @@ def problems(self, show_solved=True, show_partial=True, show_tried=False, show_u
106106 # for example:
107107 # - difficulty 9.1-9.6 -> [9.1, 9.6]
108108 # - difficulty 5.0 -> [5.0]
109- category = re .findall ('[A-Za-z]+' , columns [7 ].text )[0 ]
109+ try : category = re .findall ('[A-Za-z]+' , columns [7 ].text )[0 ]
110+ except : category = 'N/A'
110111 data .append ({
111112 'name' : name ,
112113 'fastest' : fastest ,
@@ -127,8 +128,14 @@ def plot_problems(self, filepath=None, show_solved=True, show_partial=True, show
127128 '''
128129
129130 df = pd .DataFrame (self .problems (show_solved , show_partial , show_tried , show_untried ))
130- hist = sns .histplot (data = df , x = 'difficulty' , hue = 'category' , multiple = 'stack' , binwidth = 0.1 )
131- hist .set (title = f'Solved Kattis Problems ({ df .shape [0 ]} )' , xlabel = 'Difficulty' )
131+ categories = set (df .category )
132+ hue_order = [c for c in ['Easy' , 'Medium' , 'Hard' , 'N/A' ][::- 1 ] if c in categories ]
133+ palette = {'Easy' : '#39a137' , 'Medium' : '#ffbe00' , 'Hard' : '#ff411a' , 'N/A' : 'gray' }
134+ for c in [* palette ]:
135+ if c not in categories : del palette [c ]
136+ hist = sns .histplot (data = df , x = 'difficulty' , hue = 'category' , multiple = 'stack' , binwidth = 0.1 , hue_order = hue_order , palette = palette )
137+ hist .set (title = f'Solved Kattis Problems by { self .user } ({ df .shape [0 ]} )' , xlabel = 'Difficulty' )
138+ plt .legend (title = 'Category' , loc = 'upper right' , labels = hue_order [::- 1 ])
132139 plt .xticks ([* range (math .floor (min (df .difficulty )), math .ceil (max (df .difficulty ))+ 1 )])
133140 if filepath != None :
134141 plt .savefig (filepath )
0 commit comments