Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. counter = 1
  2. def generate_trail(df):
  3. global counter
  4. court = plt.imread("fullcourt.png")
  5. fig, ax = plt.subplots(figsize=(15, 11.5))
  6. plt.imshow(court, zorder=0, extent=[-47,47,-25,25])
  7. ax.set_xlim([-47, 0])
  8. ax.set_ylim([-25, 25])
  9. scat1 = ax.scatter([], [], color="red", alpha=0.4)
  10. first_frame = df.iloc[0]
  11. attacking = first_frame['Possession']
  12. is_home_team_attacking = is_home_team(attacking, Game_id)
  13.  
  14. def sub_animate(j, frame, total_frames):
  15. x1, y1 = tuple(zip(*[list(pair.values())[0] for pair in j[is_home_team_attacking]]))
  16. if x1[0] > 0:
  17. x1 = [-x for x in x1]
  18. ax.scatter(x1, y1, color="red", alpha= frame * 0.75 / (total_frames), marker="o")
  19.  
  20.  
  21. for i in range(0, len(df)):
  22. sub_animate(df.iloc[i], i, len(df))
  23. ax.axis('off')
  24. fig.savefig(str(counter) + "_trail.png", dpi=300)
  25. counter += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement