#!/usr/bin/env python # coding: utf-8 # In[2]: get_ipython().run_line_magic('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()) # 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()