Ah, and is there any hack or workaround on the latest version to reset the selection? Maybe simulating the double click event on an empty area of the plot. This is what I want to achieve:

I cannot find a way to do it with scattergl
This is what I’m trying, even in the version 2.12.0 with no luck
await Plotly.relayout(plotDiv, {selections: []});
await Plotly.restyle(plotDiv, {selectedpoints: [null]}, [lastSelectionSource]);
In this script I am using this instruction to trigger the repainting. But I get the same resulta than with relayout and restyle.
await Plotly.react(plotDiv, traces, layout);
The first time I use the lasso tool to make a selection, the drawn lasso remains visible, and the next selection in other plot doesn’t work properly. It gets added to the selectedIndices instead of replacing the current selection.
After that, if I select points in another plot, the selection works as expected.
However, when I make a new selection in the same plot, the lasso drawing appears again (which is normal behavior), but this causes the next selection in another plot to be aggregated with the previous selectedIndices, instead of overriding them.
I’ve attached a GIF that illustrates this behavior.
Do you know a more reliable way to implement this so that selections always replace the previous ones rather than accumulate?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Plotly 3.1.0 Grid Plot - ScatterGL</title>
<script src="https://cdn.plot.ly/plotly-3.1.0.min.js"></script>
<style>
body {margin:0; font-family:'Inter', sans-serif; background-color:#f5f5f5; height:100vh;}
.plot-container {width:100vw; height:100vh; background:white; overflow:hidden;}
</style>
</head>
<body>
<div id="plotly-plot" class="plot-container"></div>
<script>
function generateRandom(count){
return Array.from({length:count},()=>Math.floor(Math.random()*100)+1);
}
const data = {
x: generateRandom(100),
y: generateRandom(100),
x2: generateRandom(100),
y2: generateRandom(100),
x3: generateRandom(100),
y3: generateRandom(100),
x4: generateRandom(100),
y4: generateRandom(100)
};
let traces = [
{x:data.x, y:data.y, mode:'markers', type:'scattergl', marker:{size:7,color:'blue',opacity:0.7}, selected:{marker:{size:10,color:'red',opacity:1}}, unselected:{marker:{opacity:0.2}}, xaxis:'x1', yaxis:'y1'},
{x:data.x2, y:data.y2, mode:'markers', type:'scattergl', marker:{size:7,color:'green',opacity:0.7}, selected:{marker:{size:10,color:'red',opacity:1}}, unselected:{marker:{opacity:0.2}}, xaxis:'x2', yaxis:'y2'},
{x:data.x3, y:data.y3, mode:'markers', type:'scattergl', marker:{size:7,color:'red',opacity:0.7}, selected:{marker:{size:10,color:'red',opacity:1}}, unselected:{marker:{opacity:0.2}}, xaxis:'x3', yaxis:'y3'},
{x:data.x4, y:data.y4, mode:'markers', type:'scattergl', marker:{size:7,color:'purple',opacity:0.7}, selected:{marker:{size:10,color:'red',opacity:1}}, unselected:{marker:{opacity:0.2}}, xaxis:'x4', yaxis:'y4'}
];
const plotDiv = document.getElementById('plotly-plot');
let layout = {
title:'Plotly 3.1.0 Grid Plot - ScatterGL',
autosize:true,
showlegend:false,
grid:{rows:2, columns:2, pattern:'independent'},
xaxis1:{title:'X1'}, yaxis1:{title:'Y1'},
xaxis2:{title:'X2'}, yaxis2:{title:'Y2'},
xaxis3:{title:'X3'}, yaxis3:{title:'Y3'},
xaxis4:{title:'X4'}, yaxis4:{title:'Y4'},
plot_bgcolor:'white',
paper_bgcolor:'white',
hovermode:'closest',
margin:{t:40,b:40,l:30,r:30},
selectdirection:'any',
selectionrevision:0,
dragmode:'select'
};
Plotly.newPlot(plotDiv, traces, layout, {displayModeBar:true, responsive:true, scrollZoom:true, displaylogo:false});
let lastSelectionSource = null;
plotDiv.on('plotly_selected', async function(eventData){
if(!eventData || !eventData.points || eventData.points.length===0) return;
const sourceTrace = eventData.points[0].curveNumber;
const selectedIndices = Array.from(new Set(eventData.points.map(p=>p.pointIndex)));
console.log(selectedIndices);
if(lastSelectionSource !== null && lastSelectionSource !== sourceTrace){
layout.selectionrevision++;
traces[lastSelectionSource].selectedpoints = null;
await Plotly.react(plotDiv, traces, layout);
}
traces.forEach(t => t.selectedpoints = selectedIndices);
layout.selectionrevision++;
await Plotly.react(plotDiv, traces, layout);
lastSelectionSource = sourceTrace;
});
</script>
</body>
</html>

I have seen that there are some issues related to selected points in the latest versions of Plotly.js
This SO question is also related. Triggering a double click on an empty area would reset the selection. But I don’t know how to trigger that programmatically