Create animation with each frame (i.e year) having a different trace

hello,

new to plotly. I have latitude / longitude data across several years. I have done clustering on this data, and obtained cluster centers (lat/lon coordinates) for each year.

I am trying to generate a px.scatter mapbox that plots the lat / lon for each year, as well as the respective cluster centers for that year. So far, I have been able to plot the lat / lon data and ALL the cluster centers in each year; is there a way where I could separate the cluster centers into their respective frames?

Here is the code snippet:
fig = px.scatter_mapbox(result, lat=β€œLat”, lon=β€œLon”, animation_frame = β€˜Year’,
color_discrete_sequence=[β€œfuchsia”], zoom = 8, color=all_kmedLabels, height=500)
fig.update_layout(mapbox_style=β€œopen-street-map”)
fig.update_layout(margin={β€œr”:0,β€œt”:0,β€œl”:0,β€œb”:0})

fig.add_trace(go.Scattermapbox(
lat=all_med_centroids[:,0], # this adds the trace to all years, but we want it separate for each yr.
lon=all_med_centroids[:,1], #
mode=β€˜markers’,
marker=go.scattermapbox.Marker(
size=10,
color=β€˜rgb(255, 255, 255)’,
opacity=1
),
))

I have viewed this but it doesnt look like it worked for me: https://chart-studio.plotly.com/~empet/14825/scattermapbox-animation-forum-question/#/