Unselect points when click empty area

If I’m using the selection tool for my scatterplot and I click a selection then the selected points stay current opacity. Then if I click outside of that selection say at an empty area, I want the selection box to disappear and all the points to go back to having the opacity they had before being selected.

Currently, if I double click, it will do what I want it to do.

// this is written in Coffeescript

plotlyDiv.on('plotly_selected', (data) ->
    if data == null
       //  make points go back to normal opacity and remove selection box
)

Based on this case
How can I remove plotly select box after the selection is done

I came up with a solution:
https://jsfiddle.net/destradafilm/7ct5kgj2/

The solutions above don’t work for me. Here is my solution:

https://jsfiddle.net/8s49c4jo/1/

The trick is setting the traces selectedpoints attribute to null:

Plotly.restyle(graphDiv, {selectedpoints: [null]});
2 Likes

The above solution does not work anymore in latest versions 2.32.0 and 2.33.0

@henning in 2.34.0 the following works, might want to give this a try if you haven’t sourced the solution already.

Plotly.relayout(graphDiv, {selections: []});