'Lasso feature for plotly scatter not working properly with animation frames

I recreated the example from Intro to Animations in Python in the Jupyter notebook:

import plotly.express as px
df = px.data.gapminder()

px.scatter(df, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country",
           size="pop", color="continent", hover_name="country",
           log_x=True, size_max=55, range_x=[100,100000], range_y=[25,90])

then I used the 'lasso' feature to highlight one of the points and moved the animation frames to check if its consistent. It worked just fine, but when I changed anything in the dataset, for example:

import plotly.express as px
df = px.data.gapminder()

px.scatter(df.sort_values(by='year'), x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country",
               size="pop", color="continent", hover_name="country",
               log_x=True, size_max=55, range_x=[100,100000], range_y=[25,90])

The highlighted points would change between frames. I then tried it on some other datasets and it does not seem to work on them no matter what I do, so it seams it works only in very specific data setting. Either that or I'm missing something important here. Does anyone know what is going on?

I'm using:

plotly           : 5.5.0
jupyter core     : 4.5.0    
jupyter-notebook : 6.0.1    
qtconsole        : not installed    
ipython          : 7.11.1    
ipykernel        : 5.1.2


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source