How to clear annotations
When creating annotations like below
fig['layout']['annotations'] = go.Annotations([])
for i in list_of_dictionaries:
fig['layout']['annotations'].append(go.Annotation(i))
in the first run of the script, the rendering of the annotations is correct: correct rendering
However, on a second run, with a different list of dictionaries, the new annotations are rendered correctly but without clearing the old annotations duplicate annotations
Isn't go.Annotations([]) suppose to initialize with an empty list?
Am I doing something wrong?
Any thoughts on the above?
Hey @rgeos We have an example here that you may be interested in that demonstrates how to add multiple annotations to a chart via a loop. If this doesn't help, you can share your full code and we can help you figure out why annotations from the first run aren't clearing properly.
Hi all, I was searching a lot for solution for my issue and seems I have problem mentioned in this issue. I am using plotly 4.6.0 and seems updating annotations still does not work. I am trying to plot heatmap with annotations
but can not update annotations when adding additional row/columns.
I have tried different code but no sucess
option1:
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
)
option2:
corr_text = np.around(corr.values, decimals=2)
font_colors = ['white', 'black']
x = y = corr.columns.tolist()
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'
@AnitsaYovanovska can you please create a new issue describing what you are trying to do exactly?
I have opened new issue Update annotated heatmap bug #2948. Thank you!