Skip to main content

plotting shot charts from basketball-reference.com

Project description

Shot Chart

Python module to plot NBA shot chart data and distributions for players and teams and some utilities.

This file will become your README and also the index of your documentation.

Install

pip install shot_chart

How to use

We first create a pandas dataframe from the source data.

shots_2019 = make_df(untar_data(URLs.SHOTS_2019))

Listing teams for the season

list_teams(shots_2019)
0            Atlanta
1            Orlando
183       Sacramento
184             Utah
341         Oklahoma
343     Golden State
511           Denver
512      New Orleans
675        Milwaukee
1016        Portland
1224         Phoenix
1226        Brooklyn
1412     San Antonio
1413         Memphis
1934         Toronto
2119    Philadelphia
2296       Minnesota
2477       LA Lakers
2655         Houston
2656     LA Clippers
2843       Charlotte
3017          Boston
3018      Washington
3383         Detroit
3918           Miami
5020       Cleveland
5535         Indiana
6407        New York
6410         Chicago
8473          Dallas
Name: team, dtype: object

Listing players who took at least 1 shot for a particular team

list_team_players(shots_2019, 'Portland')
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}
</style>
shots_by count
2 CJ McCollum 1212
5 Damian Lillard 1158
4 Carmelo Anthony 678
7 Hassan Whiteside 676
0 Anfernee Simons 522
6 Gary Trent 349
9 Kent Bazemore 322
10 Mario Hezonja 188
13 Rodney Hood 172
15 Trevor Ariza 159
12 Nassir Little 151
14 Skal Labissière 147
1 Anthony Tolliver 117
3 Caleb Swanigan 43
8 Jaylen Hoard 32
16 Wenyen Gabriel 29
17 Zach Collins 19
11 Moses Brown 10

Plotting team shot distribution

houston = TeamShots(shots_2019,"Houston")
houston.plot_shots()

png

houston.plot_shots(date_range=((2020,1,3), (2020,1,11)))

png

Please check the extra options when using the plotting functions

portland_20191125 = TeamShots(shots_2019,"Portland")
portland_20191125.list_game_ids(2019,11,25)
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}
</style>
game_id winner loser
45560 201911250CHI Portland Chicago
portland_20191125.plot_shots("201911250CHI")

png

Plotting player shot distribution

player_shots = PlayerShots(shots_2019,"Anthony Davis")
player_shots.plot_shots()

png

dlo = PlayerShots(shots_2019,"D'Angelo Russell")
dlo.plot_shots()

png

dlo.plot_shots(distance_limit=(16,26),attempt="2-pointer")

png

dlo.plot_effective(most_or_least="most")

png

dlo.plot_effective(most_or_least="most",exclude=["0ft"])

png

dlo.plot_effective(most_or_least="most",min_shots="auto",exclude=['2ft'])

png

dlo.plot_effective(most_or_least="least")

png

dlo.plot_effective(most_or_least="least",min_shots="auto")

png

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shot_chart-1.1.0.tar.gz (17.4 kB view hashes)

Uploaded Source

Built Distribution

shot_chart-1.1.0-py3-none-any.whl (14.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page