In [2]:
%matplotlib inline
In [3]:
import requests
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
shot_chart_url = 'http://stats.nba.com/stats/shotchartdetail?CFID=33&CFPAR'\
                'AMS=2014-15&ContextFilter=&ContextMeasure=FGA&DateFrom=&D'\
                'ateTo=&GameID=&GameSegment=&LastNGames=0&LeagueID=00&Loca'\
                'tion=&MeasureType=Base&Month=0&OpponentTeamID=0&Outcome=&'\
                'PaceAdjust=N&PerMode=PerGame&Period=0&PlayerID=201935&Plu'\
                'sMinus=N&Position=&Rank=N&RookieYear=&Season=2014-15&Seas'\
                'onSegment=&SeasonType=Regular+Season&TeamID=0&VsConferenc'\
                'e=&VsDivision=&mode=Advanced&showDetails=0&showShots=1&sh'\
                'owZones=0'
In [4]:
# Get the webpage containing the data
response = requests.get(shot_chart_url)
# Grab the headers to be used as column headers for our DataFrame
headers = response.json()['resultSets'][0]['headers']
# Grab the shot chart data
shots = response.json()['resultSets'][0]['rowSet']
In [5]:
shot_df = pd.DataFrame(shots, columns=headers)
# View the head of the DataFrame and all its columns
from IPython.display import display
with pd.option_context('display.max_columns', None):
    display(shot_df.head())
GRID_TYPE GAME_ID GAME_EVENT_ID PLAYER_ID PLAYER_NAME TEAM_ID TEAM_NAME PERIOD MINUTES_REMAINING SECONDS_REMAINING EVENT_TYPE ACTION_TYPE SHOT_TYPE SHOT_ZONE_BASIC SHOT_ZONE_AREA SHOT_ZONE_RANGE SHOT_DISTANCE LOC_X LOC_Y SHOT_ATTEMPTED_FLAG SHOT_MADE_FLAG
0 Shot Chart Detail 0021400003 18 201935 James Harden 1610612745 Houston Rockets 1 9 58 Missed Shot Jump Shot 3PT Field Goal Right Corner 3 Right Side(R) 24+ ft. 22 226 39 1 0
1 Shot Chart Detail 0021400003 39 201935 James Harden 1610612745 Houston Rockets 1 8 25 Missed Shot Layup Shot 2PT Field Goal Restricted Area Center(C) Less Than 8 ft. 2 -15 15 1 0
2 Shot Chart Detail 0021400003 41 201935 James Harden 1610612745 Houston Rockets 1 8 21 Made Shot Jump Shot 3PT Field Goal Above the Break 3 Left Side Center(LC) 24+ ft. 25 -232 110 1 1
3 Shot Chart Detail 0021400003 95 201935 James Harden 1610612745 Houston Rockets 1 4 32 Missed Shot Jump Shot 2PT Field Goal Mid-Range Left Side Center(LC) 16-24 ft. 19 -146 135 1 0
4 Shot Chart Detail 0021400003 120 201935 James Harden 1610612745 Houston Rockets 1 2 38 Made Shot Driving Layup Shot 2PT Field Goal Restricted Area Center(C) Less Than 8 ft. 2 -8 22 1 1
In [6]:
sns.set_style("white")
sns.set_color_codes()
plt.figure(figsize=(12,11))
plt.scatter(shot_df.LOC_X, shot_df.LOC_Y)
plt.show()
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/collections.py:590: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if self._edgecolors == str('face'):