I have a dataframe with football player stats including value X for the x-axis, Y for the y-axis, and then player name and ‘year of stats’. I’m using year of stats for the animation frame, but i want to specifically follow one player over the course of the animation to see their stats move across the fig.
d = {'player_names': ['player_A','player_A', 'player_B', 'player_B','player_C','player_C'],
'player_stat_x': ['10', '15', '5', '8', '7', '9'],
'player_stat_y':['1', '3', '2', '1', '4', '4'],
'player_year': ['2003', '2004','2003', '2004','2003', '2004']}
df = pd.DataFrame(data=d)
fig = px.scatter(df.sort_values(['player_year']),
x="player_stat_x",
y="player_stat_y",
animation_frame = "player_year",
text = ??
)
I’m trying to follow player A from year 2003 -> 2004, but i’m not sure how to approach this. Putting the ‘player_names’ column into the text field shows all names, which is not what i want. I only want the name for player_A to be showing. I’m new to plotly and lost on how to get this kind of result, or if it’s even possible.