I’m using px.scatter to create an animated dot plot that goes through the years with the play button.
fig = px.scatter(df, x="Rate", y="Country Name", color="Gender", animation_frame="Year", range_x=[4,19], range_y=[-0.5,4.5] )
That works beautifully; however, I’m trying to change the default color of the markers for both genders (male,female).
If I run the script below:
fig.data['marker'].update(color='#bff68e') #green fig.data['marker'].update(color='#fda026') #orange
the color changes correctly for both gender markers, but only for the FIRST frame. The subsequent frames go back to their default color. So I created a FOR loop to go over all the frames:
for x in fig.frames: x.data['marker']['color'] = '#bff68e' x.data['marker']['color'] = '#fda026'
This works fine. But I was wondering, Is there a faster and simpler way to update the marker color for all frames without creating a for loop?