{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"markdown","source":"# Plotting The Court\nKaggle and the NCAA have provided event day for seasons 2015-2020. In this notebook I provide some helper functions for plotting these events on a \"court\" using python. Please feel free to use these plots in your code, just reference this kernel when you do so.\n\n![](https://bringmethenews.com/.image/t_share/MTYyOTQ1NjEzMTkxNzE4NzUz/screen-shot-2019-03-27-at-113420-am.jpg)"},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"# Required libraries\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pylab as plt\nimport matplotlib as mpl\nfrom matplotlib.patches import Circle, Rectangle, Arc\nimport seaborn as sns\nplt.style.use('seaborn-dark-palette')\nmypal = plt.rcParams['axes.prop_cycle'].by_key()['color'] # Grab the color pal\n\nimport os\nimport gc\n\nMENS_DIR = '../input/google-cloud-ncaa-march-madness-2020-division-1-mens-tournament'\nWOMENS_DIR = '../input/google-cloud-ncaa-march-madness-2020-division-1-womens-tournament'","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# 1. Loading Event Data"},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"mens_events = []\nfor year in [2015, 2016, 2017, 2018, 2019]:\n    mens_events.append(pd.read_csv(f'{MENS_DIR}/MEvents{year}.csv'))\nMEvents = pd.concat(mens_events)\n\nwomens_events = []\nfor year in [2015, 2016, 2017, 2018, 2019]:\n    womens_events.append(pd.read_csv(f'{WOMENS_DIR}/WEvents{year}.csv'))\nWEvents = pd.concat(womens_events)\n\nMPlayers = pd.read_csv(f'{MENS_DIR}/MPlayers.csv')\nWPlayers = pd.read_csv(f'{WOMENS_DIR}/WPlayers.csv')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## 1b. Formatting Event Data\nIn this section we:\n- Add Area names to the data\n- Create X_ and Y_ features used for plotting on the full court plots\n- Crate X_half_ and Y_half_ features used for plotting on half court.\n- Add Player Names to event data"},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"# Area Mapping Names\narea_mapping = {0: np.nan,\n                1: 'under basket',\n                2: 'in the paint',\n                3: 'inside right wing',\n                4: 'inside right',\n                5: 'inside center',\n                6: 'inside left',\n                7: 'inside left wing',\n                8: 'outside right wing',\n                9: 'outside right',\n                10: 'outside center',\n                11: 'outside left',\n                12: 'outside left wing',\n                13: 'backcourt'}\n\nMEvents['Area_Name'] = MEvents['Area'].map(area_mapping)\nWEvents['Area_Name'] = WEvents['Area'].map(area_mapping)\n\n# Normalize X, Y positions for court dimentions\n# Court is 50 feet wide and 94 feet end to end.\nMEvents['X_'] = (MEvents['X'] * (94/100))\nMEvents['Y_'] = (MEvents['Y'] * (50/100))\n\nWEvents['X_'] = (WEvents['X'] * (94/100))\nWEvents['Y_'] = (WEvents['Y'] * (50/100))\n\n\n# Create Half Court X/Y Features for Plotting\n# Mens\nMEvents['X_half'] = MEvents['X']\nMEvents.loc[MEvents['X'] > 50, 'X_half'] = (100 - MEvents['X'].loc[MEvents['X'] > 50])\nMEvents['Y_half'] = MEvents['Y']\nMEvents.loc[MEvents['X'] > 50, 'Y_half'] = (100 - MEvents['Y'].loc[MEvents['X'] > 50])\n\nMEvents['X_half_'] = (MEvents['X_half'] * (94/100))\nMEvents['Y_half_'] = (MEvents['Y_half'] * (50/100))\n\n# Womens\nWEvents['X_half'] = WEvents['X']\nWEvents.loc[WEvents['X'] > 50, 'X_half'] = (100 - WEvents['X'].loc[WEvents['X'] > 50])\nWEvents['Y_half'] = WEvents['Y']\nWEvents.loc[WEvents['X'] > 50, 'Y_half'] = (100 - WEvents['Y'].loc[WEvents['X'] > 50])\n\nWEvents['X_half_'] = (WEvents['X_half'] * (94/100))\nWEvents['Y_half_'] = (WEvents['Y_half'] * (50/100))\n\n# Add Player Info\nMEvents = MEvents.merge(MPlayers,\n                        how='left',\n                        left_on=['EventPlayerID'],\n                        right_on='PlayerID')\n\nWEvents = WEvents.merge(MPlayers,\n                        how='left',\n                        left_on=['EventPlayerID'],\n                        right_on='PlayerID')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# 2. Plotting Half Court"},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"def create_ncaa_half_court(ax=None, three_line='mens', court_color='#dfbb85',\n                           lw=3, lines_color='black', lines_alpha=0.5,\n                           paint_fill='blue', paint_alpha=0.4,\n                          inner_arc=False):\n    \"\"\"\n    Version 2020.2.19\n\n    Creates NCAA Basketball Half Court\n    Dimensions are in feet (Court is 97x50 ft)\n    Created by: Rob Mulla / https://github.com/RobMulla\n\n    * Note that this function uses \"feet\" as the unit of measure.\n    * NCAA Data is provided on a x range: 0, 100 and y-range 0 to 100\n    * To plot X/Y positions first convert to feet like this:\n    ```\n    Events['X_'] = (Events['X'] * (94/100))\n    Events['Y_'] = (Events['Y'] * (50/100))\n    ```\n    ax: matplotlib axes if None gets current axes using `plt.gca`\n    \n    three_line: 'mens', 'womens' or 'both' defines 3 point line plotted\n    court_color : (hex) Color of the court\n    lw : line width\n    lines_color : Color of the lines\n    lines_alpha : transparency of lines\n    paint_fill : Color inside the paint\n    paint_alpha : transparency of the \"paint\"\n    inner_arc : paint the dotted inner arc\n    \"\"\"\n    if ax is None:\n        ax = plt.gca()\n\n    # Create Pathes for Court Lines\n    center_circle = Circle((50/2, 94/2), 6,\n                           linewidth=lw, color=lines_color, lw=lw,\n                           fill=False, alpha=lines_alpha)\n    hoop = Circle((50/2, 5.25), 1.5 / 2,\n                       linewidth=lw, color=lines_color, lw=lw,\n                       fill=False, alpha=lines_alpha)\n\n    # Paint - 18 Feet 10 inches which converts to 18.833333 feet - gross!\n    paint = Rectangle(((50/2)-6, 0), 12, 18.833333,\n                           fill=paint_fill, alpha=paint_alpha,\n                           lw=lw, edgecolor=None)\n    \n    paint_boarder = Rectangle(((50/2)-6, 0), 12, 18.833333,\n                           fill=False, alpha=lines_alpha,\n                           lw=lw, edgecolor=lines_color)\n    \n    arc = Arc((50/2, 18.833333), 12, 12, theta1=-\n                   0, theta2=180, color=lines_color, lw=lw,\n                   alpha=lines_alpha)\n    \n    block1 = Rectangle(((50/2)-6-0.666, 7), 0.666, 1, \n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    block2 = Rectangle(((50/2)+6, 7), 0.666, 1, \n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    ax.add_patch(block1)\n    ax.add_patch(block2)\n    \n    l1 = Rectangle(((50/2)-6-0.666, 11), 0.666, 0.166,\n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    l2 = Rectangle(((50/2)-6-0.666, 14), 0.666, 0.166,\n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    l3 = Rectangle(((50/2)-6-0.666, 17), 0.666, 0.166,\n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    ax.add_patch(l1)\n    ax.add_patch(l2)\n    ax.add_patch(l3)\n    l4 = Rectangle(((50/2)+6, 11), 0.666, 0.166,\n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    l5 = Rectangle(((50/2)+6, 14), 0.666, 0.166,\n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    l6 = Rectangle(((50/2)+6, 17), 0.666, 0.166,\n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    ax.add_patch(l4)\n    ax.add_patch(l5)\n    ax.add_patch(l6)\n    \n    # 3 Point Line\n    if (three_line == 'mens') | (three_line == 'both'):\n        # 22' 1.75\" distance to center of hoop\n        three_pt = Arc((50/2, 6.25), 44.291, 44.291, theta1=12,\n                            theta2=168, color=lines_color, lw=lw,\n                            alpha=lines_alpha)\n\n        # 4.25 feet max to sideline for mens\n        ax.plot((3.34, 3.34), (0, 11.20),\n                color=lines_color, lw=lw, alpha=lines_alpha)\n        ax.plot((50-3.34, 50-3.34), (0, 11.20),\n                color=lines_color, lw=lw, alpha=lines_alpha)\n        ax.add_patch(three_pt)\n\n    if (three_line == 'womens') | (three_line == 'both'):\n        # womens 3\n        three_pt_w = Arc((50/2, 6.25), 20.75 * 2, 20.75 * 2, theta1=5,\n                              theta2=175, color=lines_color, lw=lw, alpha=lines_alpha)\n        # 4.25 inches max to sideline for mens\n        ax.plot( (4.25, 4.25), (0, 8), color=lines_color,\n                lw=lw, alpha=lines_alpha)\n        ax.plot((50-4.25, 50-4.25), (0, 8.1),\n                color=lines_color, lw=lw, alpha=lines_alpha)\n\n        ax.add_patch(three_pt_w)\n\n    # Add Patches\n    ax.add_patch(paint)\n    ax.add_patch(paint_boarder)\n    ax.add_patch(center_circle)\n    ax.add_patch(hoop)\n    ax.add_patch(arc)\n    \n    if inner_arc:\n        inner_arc = Arc((50/2, 18.833333), 12, 12, theta1=180,\n                             theta2=0, color=lines_color, lw=lw,\n                       alpha=lines_alpha, ls='--')\n        ax.add_patch(inner_arc)\n\n    # Restricted Area Marker\n    restricted_area = Arc((50/2, 6.25), 8, 8, theta1=0,\n                        theta2=180, color=lines_color, lw=lw,\n                        alpha=lines_alpha)\n    ax.add_patch(restricted_area)\n    \n    # Backboard\n    ax.plot(((50/2) - 3, (50/2) + 3), (4, 4),\n            color=lines_color, lw=lw*1.5, alpha=lines_alpha)\n    ax.plot( (50/2, 50/2), (4.3, 4), color=lines_color,\n            lw=lw, alpha=lines_alpha)\n\n    # Half Court Line\n    ax.axhline(94/2, color=lines_color, lw=lw, alpha=lines_alpha)\n\n    \n    # Plot Limit\n    ax.set_xlim(0, 50)\n    ax.set_ylim(0, 94/2 + 2)\n    ax.set_facecolor(court_color)\n    ax.set_xticks([])\n    ax.set_yticks([])\n    ax.set_xlabel('')\n    return ax\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(11, 11.2))\ncreate_ncaa_half_court(ax,\n                       three_line='both',\n                       paint_alpha=0.4,\n                       inner_arc=True)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, axs = plt.subplots(2, 3, figsize=(15, 10))\ncolor_schemes = [['#93B7BE', '#048A81', '#2D3047'], # court, paint, lines\n                ['#BFC0C0', '#7DC95E', '#648767'],\n                ['#DDA448', '#BB342F', '#8D6A9F'],\n                ['#13505B', '#ED4848', '#ED4848'],\n                ['#161A32', '#D9DCD6', '#EAF2EF'],\n                ['#020202', '#E54424', '#FFFFFF']]\nidx = 0\nfor ax in axs.reshape(-1):\n    create_ncaa_half_court(ax,\n                           three_line='both',\n                           paint_alpha=0.1,\n                           inner_arc=True,\n                           court_color=color_schemes[idx][0],\n                           paint_fill=color_schemes[idx][1],\n                           lines_color=color_schemes[idx][2],\n                           lw=1.5)\n    idx += 1\n\nplt.tight_layout()\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Half Court Example\nfig, ax = plt.subplots(figsize=(13.8, 14))\nMEvents \\\n    .query('Y_ != 0') \\\n    .plot(x='Y_half_', y='X_half_', style='.',\n          kind='scatter', ax=ax,\n          color='orange', alpha=0.05)\ncreate_ncaa_half_court(ax, court_color='black',\n                       lines_color='white', paint_alpha=0,\n                       inner_arc=True)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Made and Missed shots dataframes\nWMadeShots = WEvents.query('EventType == \"made2\" or EventType == \"made3\"')\nWMissedShots = WEvents.query('EventType == \"miss2\" or EventType == \"miss3\"')\n\nfig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 7))\nax1 = create_ncaa_half_court(ax=ax1,\n                             three_line='womens',\n                             court_color='white',\n                             paint_alpha=0,\n                             inner_arc=True)\nax2 = create_ncaa_half_court(ax=ax2,\n                             three_line='womens',\n                             court_color='white',\n                             paint_alpha=0,\n                             inner_arc=True)\nhb1 = ax1.hexbin(x=WMadeShots.query('Y_ != 0')['Y_half_'],\n                 y=WMadeShots.query('Y_ != 0')['X_half_'],\n                 gridsize=20, bins='log', cmap='inferno')\nhb2 = ax2.hexbin(x=WMissedShots.query('Y_ != 0')['Y_half_'],\n                 y=WMissedShots.query('Y_ != 0')['X_half_'],\n                 gridsize=20, bins='log', cmap='inferno')\nax1.set_title('Womens NCAA Made Shots', size=15)\nax2.set_title('Womens NCAA Missed Shots', size=15)\ncb1 = fig.colorbar(hb1, ax=ax1)\ncb1 = fig.colorbar(hb2, ax=ax2)\nplt.tight_layout()\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"markdown","source":"# 3. Plotting Full Court"},{"metadata":{"_kg_hide-output":false,"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"def create_ncaa_full_court(ax=None, three_line='mens', court_color='#dfbb85',\n                           lw=3, lines_color='black', lines_alpha=0.5,\n                           paint_fill='blue', paint_alpha=0.4,\n                           inner_arc=False):\n    \"\"\"\n    Version 2020.2.19\n    Creates NCAA Basketball Court\n    Dimensions are in feet (Court is 97x50 ft)\n    Created by: Rob Mulla / https://github.com/RobMulla\n\n    * Note that this function uses \"feet\" as the unit of measure.\n    * NCAA Data is provided on a x range: 0, 100 and y-range 0 to 100\n    * To plot X/Y positions first convert to feet like this:\n    ```\n    Events['X_'] = (Events['X'] * (94/100))\n    Events['Y_'] = (Events['Y'] * (50/100))\n    ```\n    \n    ax: matplotlib axes if None gets current axes using `plt.gca`\n\n\n    three_line: 'mens', 'womens' or 'both' defines 3 point line plotted\n    court_color : (hex) Color of the court\n    lw : line width\n    lines_color : Color of the lines\n    lines_alpha : transparency of lines\n    paint_fill : Color inside the paint\n    paint_alpha : transparency of the \"paint\"\n    inner_arc : paint the dotted inner arc\n    \"\"\"\n    if ax is None:\n        ax = plt.gca()\n\n    # Create Pathes for Court Lines\n    center_circle = Circle((94/2, 50/2), 6,\n                           linewidth=lw, color=lines_color, lw=lw,\n                           fill=False, alpha=lines_alpha)\n    hoop_left = Circle((5.25, 50/2), 1.5 / 2,\n                       linewidth=lw, color=lines_color, lw=lw,\n                       fill=False, alpha=lines_alpha)\n    hoop_right = Circle((94-5.25, 50/2), 1.5 / 2,\n                        linewidth=lw, color=lines_color, lw=lw,\n                        fill=False, alpha=lines_alpha)\n\n    # Paint - 18 Feet 10 inches which converts to 18.833333 feet - gross!\n    left_paint = Rectangle((0, (50/2)-6), 18.833333, 12,\n                           fill=paint_fill, alpha=paint_alpha,\n                           lw=lw, edgecolor=None)\n    right_paint = Rectangle((94-18.83333, (50/2)-6), 18.833333,\n                            12, fill=paint_fill, alpha=paint_alpha,\n                            lw=lw, edgecolor=None)\n    \n    left_paint_boarder = Rectangle((0, (50/2)-6), 18.833333, 12,\n                           fill=False, alpha=lines_alpha,\n                           lw=lw, edgecolor=lines_color)\n    right_paint_boarder = Rectangle((94-18.83333, (50/2)-6), 18.833333,\n                            12, fill=False, alpha=lines_alpha,\n                            lw=lw, edgecolor=lines_color)\n\n    left_arc = Arc((18.833333, 50/2), 12, 12, theta1=-\n                   90, theta2=90, color=lines_color, lw=lw,\n                   alpha=lines_alpha)\n    right_arc = Arc((94-18.833333, 50/2), 12, 12, theta1=90,\n                    theta2=-90, color=lines_color, lw=lw,\n                    alpha=lines_alpha)\n    \n    leftblock1 = Rectangle((7, (50/2)-6-0.666), 1, 0.666,\n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    leftblock2 = Rectangle((7, (50/2)+6), 1, 0.666,\n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    ax.add_patch(leftblock1)\n    ax.add_patch(leftblock2)\n    \n    left_l1 = Rectangle((11, (50/2)-6-0.666), 0.166, 0.666,\n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    left_l2 = Rectangle((14, (50/2)-6-0.666), 0.166, 0.666,\n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    left_l3 = Rectangle((17, (50/2)-6-0.666), 0.166, 0.666,\n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    ax.add_patch(left_l1)\n    ax.add_patch(left_l2)\n    ax.add_patch(left_l3)\n    left_l4 = Rectangle((11, (50/2)+6), 0.166, 0.666,\n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    left_l5 = Rectangle((14, (50/2)+6), 0.166, 0.666,\n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    left_l6 = Rectangle((17, (50/2)+6), 0.166, 0.666,\n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    ax.add_patch(left_l4)\n    ax.add_patch(left_l5)\n    ax.add_patch(left_l6)\n    \n    rightblock1 = Rectangle((94-7-1, (50/2)-6-0.666), 1, 0.666,\n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    rightblock2 = Rectangle((94-7-1, (50/2)+6), 1, 0.666,\n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    ax.add_patch(rightblock1)\n    ax.add_patch(rightblock2)\n\n    right_l1 = Rectangle((94-11, (50/2)-6-0.666), 0.166, 0.666,\n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    right_l2 = Rectangle((94-14, (50/2)-6-0.666), 0.166, 0.666,\n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    right_l3 = Rectangle((94-17, (50/2)-6-0.666), 0.166, 0.666,\n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    ax.add_patch(right_l1)\n    ax.add_patch(right_l2)\n    ax.add_patch(right_l3)\n    right_l4 = Rectangle((94-11, (50/2)+6), 0.166, 0.666,\n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    right_l5 = Rectangle((94-14, (50/2)+6), 0.166, 0.666,\n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    right_l6 = Rectangle((94-17, (50/2)+6), 0.166, 0.666,\n                           fill=True, alpha=lines_alpha,\n                           lw=0, edgecolor=lines_color,\n                           facecolor=lines_color)\n    ax.add_patch(right_l4)\n    ax.add_patch(right_l5)\n    ax.add_patch(right_l6)\n    \n    # 3 Point Line\n    if (three_line == 'mens') | (three_line == 'both'):\n        # 22' 1.75\" distance to center of hoop\n        three_pt_left = Arc((6.25, 50/2), 44.291, 44.291, theta1=-78,\n                            theta2=78, color=lines_color, lw=lw,\n                            alpha=lines_alpha)\n        three_pt_right = Arc((94-6.25, 50/2), 44.291, 44.291,\n                             theta1=180-78, theta2=180+78,\n                             color=lines_color, lw=lw, alpha=lines_alpha)\n\n        # 4.25 feet max to sideline for mens\n        ax.plot((0, 11.25), (3.34, 3.34),\n                color=lines_color, lw=lw, alpha=lines_alpha)\n        ax.plot((0, 11.25), (50-3.34, 50-3.34),\n                color=lines_color, lw=lw, alpha=lines_alpha)\n        ax.plot((94-11.25, 94), (3.34, 3.34),\n                color=lines_color, lw=lw, alpha=lines_alpha)\n        ax.plot((94-11.25, 94), (50-3.34, 50-3.34),\n                color=lines_color, lw=lw, alpha=lines_alpha)\n        ax.add_patch(three_pt_left)\n        ax.add_patch(three_pt_right)\n\n    if (three_line == 'womens') | (three_line == 'both'):\n        # womens 3\n        three_pt_left_w = Arc((6.25, 50/2), 20.75 * 2, 20.75 * 2, theta1=-85,\n                              theta2=85, color=lines_color, lw=lw, alpha=lines_alpha)\n        three_pt_right_w = Arc((94-6.25, 50/2), 20.75 * 2, 20.75 * 2,\n                               theta1=180-85, theta2=180+85,\n                               color=lines_color, lw=lw, alpha=lines_alpha)\n\n        # 4.25 inches max to sideline for mens\n        ax.plot((0, 8.3), (4.25, 4.25), color=lines_color,\n                lw=lw, alpha=lines_alpha)\n        ax.plot((0, 8.3), (50-4.25, 50-4.25),\n                color=lines_color, lw=lw, alpha=lines_alpha)\n        ax.plot((94-8.3, 94), (4.25, 4.25),\n                color=lines_color, lw=lw, alpha=lines_alpha)\n        ax.plot((94-8.3, 94), (50-4.25, 50-4.25),\n                color=lines_color, lw=lw, alpha=lines_alpha)\n\n        ax.add_patch(three_pt_left_w)\n        ax.add_patch(three_pt_right_w)\n\n    # Add Patches\n    ax.add_patch(left_paint)\n    ax.add_patch(left_paint_boarder)\n    ax.add_patch(right_paint)\n    ax.add_patch(right_paint_boarder)\n    ax.add_patch(center_circle)\n    ax.add_patch(hoop_left)\n    ax.add_patch(hoop_right)\n    ax.add_patch(left_arc)\n    ax.add_patch(right_arc)\n    \n    if inner_arc:\n        left_inner_arc = Arc((18.833333, 50/2), 12, 12, theta1=90,\n                             theta2=-90, color=lines_color, lw=lw,\n                       alpha=lines_alpha, ls='--')\n        right_inner_arc = Arc((94-18.833333, 50/2), 12, 12, theta1=-90,\n                        theta2=90, color=lines_color, lw=lw,\n                        alpha=lines_alpha, ls='--')\n        ax.add_patch(left_inner_arc)\n        ax.add_patch(right_inner_arc)\n\n    # Restricted Area Marker\n    restricted_left = Arc((6.25, 50/2), 8, 8, theta1=-90,\n                        theta2=90, color=lines_color, lw=lw,\n                        alpha=lines_alpha)\n    restricted_right = Arc((94-6.25, 50/2), 8, 8,\n                         theta1=180-90, theta2=180+90,\n                         color=lines_color, lw=lw, alpha=lines_alpha)\n    ax.add_patch(restricted_left)\n    ax.add_patch(restricted_right)\n    \n    # Backboards\n    ax.plot((4, 4), ((50/2) - 3, (50/2) + 3),\n            color=lines_color, lw=lw*1.5, alpha=lines_alpha)\n    ax.plot((94-4, 94-4), ((50/2) - 3, (50/2) + 3),\n            color=lines_color, lw=lw*1.5, alpha=lines_alpha)\n    ax.plot((4, 4.6), (50/2, 50/2), color=lines_color,\n            lw=lw, alpha=lines_alpha)\n    ax.plot((94-4, 94-4.6), (50/2, 50/2),\n            color=lines_color, lw=lw, alpha=lines_alpha)\n\n    # Half Court Line\n    ax.axvline(94/2, color=lines_color, lw=lw, alpha=lines_alpha)\n\n    # Boarder\n    boarder = Rectangle((0.3,0.3), 94-0.4, 50-0.4, fill=False, lw=3, color='black', alpha=lines_alpha)\n    ax.add_patch(boarder)\n    \n    # Plot Limit\n    ax.set_xlim(0, 94)\n    ax.set_ylim(0, 50)\n    ax.set_facecolor(court_color)\n    ax.set_xticks([])\n    ax.set_yticks([])\n    ax.set_xlabel('')\n    return ax","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Example to make plot\nfig, ax = plt.subplots(figsize=(15, 8))\ncreate_ncaa_full_court(ax,\n                       three_line='both',\n                       paint_alpha=0.4,\n                       inner_arc=True)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Example adding data \nfig, ax = plt.subplots(figsize=(15, 8))\ncreate_ncaa_full_court(ax,\n                       three_line='both',\n                       paint_alpha=0.4,\n                       inner_arc=True)\nfor i, d in MEvents.query('PlayerID == 13061 and X_ != 0').groupby('EventType'):\n    d.plot(x='X_', y='Y_', style='X', ax=ax, label=i, alpha=1)\n    plt.legend()\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Example with different color schemes\nfig, axs = plt.subplots(3, 2, figsize=(15, 13))\ncolor_schemes = [['#93B7BE', '#048A81', '#2D3047'], # court, paint, lines\n                ['#BFC0C0', '#7DC95E', '#648767'],\n                ['#DDA448', '#BB342F', '#8D6A9F'],\n                ['#13505B', '#ED4848', '#ED4848'],\n                ['#161A32', '#D9DCD6', '#EAF2EF'],\n                ['#020202', '#E54424', '#FFFFFF']]\nidx = 0\nfor ax in axs.reshape(-1):\n    create_ncaa_full_court(ax,\n                           three_line='both',\n                           paint_alpha=0.1,\n                           inner_arc=True,\n                           court_color=color_schemes[idx][0],\n                           paint_fill=color_schemes[idx][1],\n                           lines_color=color_schemes[idx][2],\n                           lw=1.5)\n    idx += 1\n\nplt.tight_layout()\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"That's it! Please make use of these functions to help your analysis!"}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":1}