I would like to add annotations to the heatmap to simulate a confusion matrix, but with colors. I tried using Figure Factory’s “create_annotated_heatmap”, but I couldn’t add it as a subplot. I would like to add annotations to the graphics_object heatmap.
Thanks!
Note: none of the names/titles for the graphs make sense yet, I just have them as placeholders.
Here is the code:
confidence = 0.91
Accuracy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
Learning = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
FScore = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
fig = go.Figure()
fig = make_subplots(rows=2, cols=2,
specs=[[{“type”: “pie”}, {“type”: “scatter”}],[{“type”: “heatmap”}, {“type”: “scatter”}]],
subplot_titles=(“Confidence Score”, “Algorithm Accuracy”, “Learning Over Time”, “F-Score”))
names = [“Confidence”, “Doubt”]
pie_chart_values =[confidence, 1-confidence]
#pie chart
fig.add_trace(go.Pie(values = pie_chart_values,name = ‘Gaps0’, labels = names,
marker = dict(colors = [‘darkblue’, ‘royalblue’]),
outsidetextfont = dict(color = ‘#ffffff’,
size = 20),
insidetextfont = dict(color = [’#ffffff’, ‘#ffffff’],
size = 20)),
row = 1, col=1
)
#accuracy graph
fig.add_trace(go.Scatter(
x=Accuracy,
y=[5, 15, 10, 10, 5, 0, 10, 10, 15, 5, 5, 10, 20, 15, 5],
name=‘Gaps’,
mode = ‘lines’,
line = dict(width = 10,
color = ‘#0458de’),
),
row=1, col=2
)
##////
##////
##////
#Confusion Matrix
z = [[200, 450],[648, 2]] ##bottom
x = [‘True’, ‘False’]
y = [‘False’, ‘True’]
z_text = [[str(y) for y in x] for x in z]
fig.add_trace(go.Heatmap(z=z, x=x, y=y, text=z_text,
showscale = False,
name = ‘Heatmap’,
colorscale=‘Blues’,
hoverlabel = dict(bgcolor = ‘white’)),
row=2, col=1
)
##////
##////
##////
#F-Score
fig.add_trace(go.Scatter(
x=FScore,
y=[5, 15, 10, 10, 5, 0, 10, 10, 15, 5, 5, 10, 20, 15, 5],
mode = ‘lines’,
name = “Accruacy Estimate”,
line = dict(width = 10,
color = ‘#68b0f2’)
),
row=2, col=2
)
for annotation in fig[‘layout’][‘annotations’]:
annotation[‘y’] = annotation[‘y’] +0.05
fig[‘layout’][‘annotations’][0][‘font’].update(color=’#ffffff’,
size = 24)
fig[‘layout’][‘annotations’][1][‘font’].update(color=’#ffffff’,
size = 24)
fig[‘layout’][‘annotations’][2][‘font’].update(color=’#ffffff’,
size = 24)
fig[‘layout’][‘annotations’][3][‘font’].update(color=’#ffffff’,
size = 24)
fig[‘layout’][‘legend’].update(bgcolor = ‘#ffffff’,
font = dict(color=’#000000’,
size = 16))
fig.update_layout(paper_bgcolor = ‘#5a678c’,
plot_bgcolor = ‘#5a678c’)
fig.update_xaxes(tickfont=dict(color=‘white’, size=14))
fig.update_yaxes(tickfont=dict(color=‘white’, size=14))
fig.write_html(‘tmp.html’, auto_open=True)