Update annotated heatmap bug
My problem is following: I have some dataframe for example (5, 15) - datatable in dash, on every input in the callback I have different selected number of columns/features for which I produce corr matrix and want to plot annotated heatmap. If 3 columns are selected I need annotated heatmap 3x3, if 10 are selected I need 10x10, so size is changing, on every output graph should be updated accordingly to selected data on input. I have created annotated heatmap in two ways but updating dcc.graph is not working.
On the left side I have only for example heatmap which is ok, on the right side annotated heatmap which has issue with ploting. I am using plotly 4.6.0

@app.callback([Output("corr-matrix", "figure"),
Output("annotated-corr-matrix", "figure")
],
Input("datatable", "selected_columns")
)
def update_corr_matrix(selected_col):
...calculate correlation matrix values...
corr_matrix_fig = go.Figure(data=go.Heatmap(
z=corr, x=corr.columns, y=corr.columns, colorscale='rdylbu'))
#only show rounded value (full value on hover)
corr_text = np.around(corr.values, decimals=2)
font_colors = ['white', 'black']
x = y = corr.columns.tolist()
annot_corr_matrix_fig = ff.create_annotated_heatmap(corr.values, x=x, y=y, annotation_text=corr_text, colorscale='rdylbu',
font_colors=font_colors, showscale = False)
#set xaxis to bottom
corr_matrix_fig['layout']['xaxis']['side'] = 'bottom'
return corr_matrix, annot_corr_matrix_fig
else:
return {}, {}
option 2 annotated heatmap:
x=corr.columns.tolist()
y=corr.columns.tolist()
z = corr.values
annotations = go.Annotations()
for n, row in enumerate(z):
for m, val in enumerate(row):
annotations.append(go.Annotation(text=str(z[n][m]), x=x[m], y=y[n],
xref='x1', yref='y1', showarrow=False))
trace = go.Heatmap(x=x, y=y, z=z, colorscale='rdylbu')
fig = go.Figure(data=go.Data([trace]))
fig.update_layout(
annotations=annotations
)
Can provide a runnable sample of the dataset which is causing the annotated heatmap to give such strange output? Also, is any of this resolved when upgrading to version 4.13 ?
Hi - we are trying to tidy up the stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for several years, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. Thanks for your help - @gvwilson