Skip to content

Commit d5ed9ab

Browse files
author
Harry Li
committed
summed percentages
1 parent c77f610 commit d5ed9ab

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/utils/evaluations/mintaka-wikidata/plot/validation_figures.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,28 +138,38 @@ def correctness_stacked_barchart():
138138
lambda x: algorithm_data.loc[algorithm_data['Correctness'] == x]['Value'].reset_index(drop=True),
139139
correctness))
140140

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
141143
# 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
143144
for correct_idx, correct in enumerate(correctness):
144145
values = filtered_values[correct_idx] # Series containing the values for this algorithm + correctness, by question type
145146
color = CORRECTNESS_PALETTE[f'{algorithm} {correct}'] # Get the color palette for this algorithm + correctness
146147
# Stack the bars for this correctness
147148
bar = ax.bar(
148-
x=x + (alg_idx - 0.5) * width,
149+
x=plot_x,
149150
height=values,
150151
width=width,
151152
color=color,
152-
label=f'{algorithm} {correct} Correct',
153+
label=f'{algorithm} {correct}',
153154
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+
154160
# 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)
156166

157167
ax.set_xlabel('Question Type')
158168
ax.set_ylabel('% Correct')
159-
ax.set_title('Side-by-Side Stacked Bar Chart')
169+
# ax.set_title('Side-by-Side Stacked Bar Chart')
160170
ax.set_xticks(x)
161171
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')
163173
plt.tight_layout()
164174
plt.savefig(Path(PLOTS, 'correctness_stacked.pdf'), bbox_inches='tight', format='pdf')
165175
plt.close()

0 commit comments

Comments
 (0)