Plots the NBA shot_charts and shot distribution for players, teams and the whole league.
config = Config()
Downloading¶
Extract¶
file_extract
is used by default in untar_data
to decompress the downloaded file.
URLs.path(URLs.SHOTS_2020)
shots_2020 = make_df(untar_data(URLs.SHOTS_2020))
Using the delegate
function from https://www.fast.ai/2019/08/06/delegation/¶
Creating a class - Shots¶
mycmap = plt.cm.Reds
mycmap._init()
mycmap._lut[:,-1] = np.linspace(0, 0.8, 259)
shots = Shots(shots_2020)
shots.players
viridis = plt.cm.get_cmap('viridis', 12)
print('viridis.colors', viridis.colors)
shots.plot_shots()
shots.plot_shots(date_range=((2021,4,1), (2021,4,18)))
shots.plot_shots(date_range=((2021,4,17), (2021,4,18)))
shots.list_game_ids(2021, 4, 17)
shots.plot_shots(date_range="202104170WAS")
shots.plot_effective(most_or_least="most", metric="efg")
shots.plot_effective(most_or_least="most", metric="efg", exclude=['0ft','1ft','2ft','23ft'])
shots.plot_effective(most_or_least="most", min_shots="auto",exclude=['1ft','2ft','23ft','24ft','25ft','26ft','27ft'])
shots.plot_effective(most_or_least="least", min_shots='auto',exclude=['24ft','23ft'])
List teams¶
print(list_teams(shots_2020))
List unique game ids¶
list_game_ids(shots_2020,2021,4,17)
Inheriting from Shots to create TeamShots¶
team_shots = TeamShots(shots_2020,"Portland")
team_shots.team
team_shots.plot_shots()
team_shots.plot_effective()
team_shots.dataframe.loc[(team_shots.dataframe['distance']=='24ft') & (team_shots.dataframe['attempt']=='2-pointer')]
team_shots.plot_effective(most_or_least="least")
team_shots = TeamShots(shots_2020,"Houston")
team_shots.plot_shots()
team_shots.plot_shots(date_range=((2021,1,3), (2021,1,8)))
team_shots.plot_effective("least")
team_shots = TeamShots(shots_2020,"LA Lakers")
team_shots.plot_shots()
List players who took shots for a team¶
list_team_players(shots_2020,'LA Lakers')
Inheriting from Shots to create PlayerShots¶
player_shots = PlayerShots(shots_2020,"Kevin Durant")
player_shots.fg_pct
player_shots.efg_pct
player_shots.plot_shots()
player_shots = PlayerShots(shots_2020,"Russell Westbrook")
player_shots.plot_shots(distance_limit=(16,26),attempt="2-pointer")
player_shots.plot_effective(metric="efg", exclude=['0ft','22ft',"1ft"])
player_shots.plot_effective(metric="efg", min_shots="auto",exclude=['2ft'])
player_shots = PlayerShots(shots_2020,"James Harden")
player_shots.plot_effective(metric="efg", exclude=['16ft',"0ft","11ft",'1ft'])
player_shots.plot_effective(min_shots="auto",exclude=['1ft','28ft','2ft','3ft'])
player_shots = PlayerShots(shots_2020, 'Derrick Rose')
player_shots.list_game_ids(2021,4,16)
player_shots.plot_shots()
player_shots.plot_effective()
player_shots.plot_shots(date_range='202104160DAL')