plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

How to clear annotations

Open rgeos opened this issue 10 years ago • 5 comments

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?

rgeos avatar Feb 12 '16 00:02 rgeos

Any thoughts on the above?

rgeos avatar Feb 16 '16 18:02 rgeos

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.

cldougl avatar Feb 16 '16 21:02 cldougl

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 image but can not update annotations when adding additional row/columns. image 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 avatar Nov 30 '20 12:11 AnitsaYovanovska

@AnitsaYovanovska can you please create a new issue describing what you are trying to do exactly?

nicolaskruchten avatar Nov 30 '20 18:11 nicolaskruchten

I have opened new issue Update annotated heatmap bug #2948. Thank you!

AnitsaYovanovska avatar Dec 01 '20 09:12 AnitsaYovanovska