Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- counter = 1
- def generate_trail(df):
- global counter
- court = plt.imread("fullcourt.png")
- fig, ax = plt.subplots(figsize=(15, 11.5))
- plt.imshow(court, zorder=0, extent=[-47,47,-25,25])
- ax.set_xlim([-47, 0])
- ax.set_ylim([-25, 25])
- scat1 = ax.scatter([], [], color="red", alpha=0.4)
- first_frame = df.iloc[0]
- attacking = first_frame['Possession']
- is_home_team_attacking = is_home_team(attacking, Game_id)
- def sub_animate(j, frame, total_frames):
- x1, y1 = tuple(zip(*[list(pair.values())[0] for pair in j[is_home_team_attacking]]))
- if x1[0] > 0:
- x1 = [-x for x in x1]
- ax.scatter(x1, y1, color="red", alpha= frame * 0.75 / (total_frames), marker="o")
- for i in range(0, len(df)):
- sub_animate(df.iloc[i], i, len(df))
- ax.axis('off')
- fig.savefig(str(counter) + "_trail.png", dpi=300)
- counter += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement