@@ -138,28 +138,38 @@ def correctness_stacked_barchart():
138
138
lambda x : algorithm_data .loc [algorithm_data ['Correctness' ] == x ]['Value' ].reset_index (drop = True ),
139
139
correctness ))
140
140
141
+ plot_x = x + (alg_idx - 0.5 ) * width
142
+ bottom = np .zeros (len (question_types )) # The first correctness bars will be stacked from the bottom
141
143
# Loop over all the correctness to stack the bars on top of each other
142
- bottom = None # The first correctness bars will be stacked from the bottom
143
144
for correct_idx , correct in enumerate (correctness ):
144
145
values = filtered_values [correct_idx ] # Series containing the values for this algorithm + correctness, by question type
145
146
color = CORRECTNESS_PALETTE [f'{ algorithm } { correct } ' ] # Get the color palette for this algorithm + correctness
146
147
# Stack the bars for this correctness
147
148
bar = ax .bar (
148
- x = x + ( alg_idx - 0.5 ) * width ,
149
+ x = plot_x ,
149
150
height = values ,
150
151
width = width ,
151
152
color = color ,
152
- label = f'{ algorithm } { correct } Correct ' ,
153
+ label = f'{ algorithm } { correct } ' ,
153
154
bottom = bottom )
155
+
156
+ # for xpos, value, y in zip(plot_x, values, bottom):
157
+ # if value != 0.0:
158
+ # ax.text(x=xpos, y=y + value/2, s=percent_formatter(value), ha='center', va='center', fontsize=10)
159
+
154
160
# For the next set of stacked bars, we need to add these count values so we know where we should stack from
155
- bottom = values if (bottom is None ) else (bottom + values )
161
+ bottom += values
162
+
163
+ # Label the percentage sums
164
+ for xpos , total in zip (plot_x , bottom ):
165
+ ax .text (x = xpos , y = total + 0.5 , s = percent_formatter (total ), ha = 'center' , va = 'bottom' , fontsize = 10 )
156
166
157
167
ax .set_xlabel ('Question Type' )
158
168
ax .set_ylabel ('% Correct' )
159
- ax .set_title ('Side-by-Side Stacked Bar Chart' )
169
+ # ax.set_title('Side-by-Side Stacked Bar Chart')
160
170
ax .set_xticks (x )
161
171
ax .set_xticklabels (question_types )
162
- ax .legend (bbox_to_anchor = (1.05 , 1 ), loc = 'upper left' )
172
+ ax .legend (title = "# Correct / 3 Attempts" , title_fontsize = 10 , bbox_to_anchor = (1 , 1 ), loc = 'upper left' )
163
173
plt .tight_layout ()
164
174
plt .savefig (Path (PLOTS , 'correctness_stacked.pdf' ), bbox_inches = 'tight' , format = 'pdf' )
165
175
plt .close ()
0 commit comments