Skip to content

Commit

Permalink
display_matrix text color fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MiXaiLL76 committed Aug 29, 2024
1 parent 697204d commit 77b8631
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions faster_coco_eval/extra/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,33 +306,26 @@ def display_matrix(
else:
hovertemplate += "Count: %{z:.0f}<extra></extra>"

annotations = []
for j, row in enumerate(conf_matrix):
annotations.append([])
for value in row:
text_value = "{:.0f}".format(value)
if normalize:
text_value += "%"

annotations[j].append(text_value)

heatmap = go.Heatmap(
z=conf_matrix,
x=_labels,
y=_labels[:-2],
text=annotations,
colorscale="Blues",
hovertemplate=hovertemplate,
texttemplate="%{text}",
)

annotations = []
for j, row in enumerate(conf_matrix):
for i, value in enumerate(row):
text_value = "{:.0f}".format(value)
if normalize:
text_value += "%"

annotations.append(
{
"x": _labels[i],
"y": _labels[j],
"font": {"color": "white"},
"text": text_value,
"xref": "x1",
"yref": "y1",
"showarrow": False,
}
)

title = "Confusion Matrix"
if normalize:
title = "Normalized " + title
Expand All @@ -341,7 +334,6 @@ def display_matrix(
"title": title,
"xaxis": {"title": "Predicted value"},
"yaxis": {"title": "Real value"},
"annotations": annotations,
}

fig = go.Figure(data=[heatmap], layout=layout)
Expand Down

0 comments on commit 77b8631

Please sign in to comment.