Strange behavior of scatter_mapbox

Hi,
I’m lost with the behavior of scatter_mapbox.
I have a DF with lat/lon, a date (in the form YYYY-MM-DD HH:MM:SS) and a color. I want to animate it s.t. at a given time, all rows with a given date are printed out with the associated color.

fig = px.scatter_mapbox(df,
                lat="stop_lat" ,
                lon="stop_lon",
                hover_name="stop_name",
                mapbox_style='carto-positron',
                animation_frame="current_time",
                color="route_color",
                height = 600,
                width = 800,
                zoom=11)
fig.show()

If I don’t sort by time, I have all points but the animation it’s not in the correct order (+it doesn’t respect the order)

If I sort by time, with color given, i only have few points + it doesn’t respect the colors.

Without color given, I have all the points! (but not the colors)

Is there something I do wrong?

HI @billybobz welcome!

Check the dtype of your time column of the dataframe.

dtype(‘<M8[ns]’)

Try converting it to datetime:

 pd.to_datetime()

it’s now datetime64[ns] but same behavior

OK so it’s a known bug px animations does not show correctly colors if all colors are not in the first frame · Issue #2259 · plotly/plotly.py · GitHub all the colors needs to be somewhere on the first frame…

1 Like