Python matplotlib.patches 模块,Arc() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用matplotlib.patches.Arc()

项目:NBAapi    作者:eyalshafran    | 项目源码 | 文件源码
def zones(**kwargs):
    '''
    Plots zones on the court as per NBA.com
    the plot adds to the last plot used or starts a new figure
    '''
    ax = plt.gca()
    zone1 = Arc((0, 0), 16.0, 16.0,theta1 = -41.0,theta2 = 180.0+41.0,**kwargs)
    zone2 = Arc((0, 0), 32.0, 32.0,theta1 = -19.2,theta2 = 180.0+19.2, **kwargs)
    ax.add_patch(zone1)
    ax.add_patch(zone2)
    ang = 60.0
    ax.plot([np.cos(ang/180*np.pi)*8, np.cos(ang/180*np.pi)*16],
             [np.sin(ang/180*np.pi)*8, np.sin(ang/180*np.pi)*16],**kwargs)
    ang = 120.0
    ax.plot([np.cos(ang/180*np.pi)*8, np.cos(ang/180*np.pi)*16],
             [np.sin(ang/180*np.pi)*8, np.sin(ang/180*np.pi)*16],**kwargs)
    ax.plot([22,25],[14-5.25,14-5.25],**kwargs)
    ax.plot([-22,-25],[14-5.25,14-5.25],**kwargs)
    ang = 36.0
    ax.plot([np.cos(ang/180*np.pi)*16, np.cos(ang/180*np.pi)*23.75],
             [np.sin(ang/180*np.pi)*16, np.sin(ang/180*np.pi)*23.75],**kwargs)
    ang = 72.0
    ax.plot([np.cos(ang/180*np.pi)*16, np.cos(ang/180*np.pi)*24],
             [np.sin(ang/180*np.pi)*16, np.sin(ang/180*np.pi)*24],**kwargs)
    ang = 72.0+36.0
    ax.plot([np.cos(ang/180*np.pi)*16, np.cos(ang/180*np.pi)*24],
             [np.sin(ang/180*np.pi)*16, np.sin(ang/180*np.pi)*24],**kwargs)
    ang = 72.0*2
    ax.plot([np.cos(ang/180*np.pi)*16, np.cos(ang/180*np.pi)*23.75],
             [np.sin(ang/180*np.pi)*16, np.sin(ang/180*np.pi)*23.75],**kwargs)
    ang = 72.0
    ax.plot([np.cos(ang/180*np.pi)*24, np.cos(ang/180*np.pi)*41.25],
             [np.sin(ang/180*np.pi)*24, 41.25],**kwargs)
    ang = 72.0+36.0
    ax.plot([np.cos(ang/180*np.pi)*24, np.cos(ang/180*np.pi)*41.25],
             [np.sin(ang/180*np.pi)*24, 41.25],**kwargs)
项目:nba_shot_charts    作者:Connor-R    | 项目源码 | 文件源码
def get_key_text(_type, ids, start_date, end_date, metrics):

    text = ''

    for zone in ('All', 'Above The Break 3', 'Corner 3', 'Mid-Range', 'In The Paint (Non-RA)', 'Restricted Area'):
        if zone == 'All':
            text += 'All Shots | '
        elif zone == 'Above The Break 3':
            text += '\n' + 'Arc 3 | '
        elif zone == 'In The Paint (Non-RA)':
            text += '\n' + 'Paint(Non-RA) | '
        elif zone == 'Restricted Area':
            text += '\n' + 'Restricted | '
        else:
            text += '\n' + zone + ' | '    

        atts = ("%.0f" % get_metrics(metrics, zone, 'attempts'))
        makes = ("%.0f" % get_metrics(metrics, zone, 'makes'))
        zone_pct = ("%.1f" % (float(100)*get_metrics(metrics, zone, 'z_pct')))
        zone_pct_plus = ("%.1f" % get_metrics(metrics, zone, 'zone_pct_plus'))
        efg = ("%.1f" % (float(100)*get_metrics(metrics, zone, 'efg')))
        efg_plus = ("%.1f" % get_metrics(metrics, zone, 'efg_plus'))
        zone_efg_plus = ("%.1f" % get_metrics(metrics, zone, 'ZONE_efg_plus'))
        paa = ("%.1f" % get_metrics(metrics, zone, 'paa'))
        paa_game = ("%.1f" % get_metrics(metrics, zone, 'paa_per_game'))

        if zone == 'All':
            text += str(makes) + ' for ' + str(atts) + ' | '
            text += str(efg) + ' EFG% ('
            text += str(efg_plus) + ' EFG+ | '
            text += str(paa) + ' PAA) | '
            text += str(paa_game) + ' PAA/G'
        else:
            text += str(makes) + '/' + str(atts) + ' | '
            text += str(zone_pct) + '% z% (' + str(zone_pct_plus) + ' z%+) | '
            text += str(zone_efg_plus) + ' zEFG+ ('
            text += str(efg_plus) + ' EFG+ | '
            text += str(paa) + ' PAA)'
    return text
项目:nba_shot_charts    作者:Connor-R    | 项目源码 | 文件源码
def draw_court(ax=None, color='white', lw=2, outer_lines=False):
    from matplotlib.patches import Circle, Rectangle, Arc
    if ax is None:
        ax = plt.gca()
    hoop = Circle((0, 0), radius=7.5, linewidth=lw, color=color, fill=False)
    backboard = Rectangle((-30, -7.5), 60, -1, linewidth=lw, color=color)
    outer_box = Rectangle((-80, -47.5), 160, 190, linewidth=lw, color=color,
                          fill=False)
    inner_box = Rectangle((-60, -47.5), 120, 190, linewidth=lw, color=color,
                          fill=False)
    top_free_throw = Arc((0, 142.5), 120, 120, theta1=0, theta2=180,
                         linewidth=lw, color=color, fill=False)
    bottom_free_throw = Arc((0, 142.5), 120, 120, theta1=180, theta2=0,
                            linewidth=lw, color=color, linestyle='dashed')
    restricted = Arc((0, 0), 80, 80, theta1=0, theta2=180, linewidth=lw,
                     color=color)
    corner_three_a = Rectangle((-220, -47.5), 0, 140, linewidth=lw,
                               color=color)
    corner_three_b = Rectangle((220, -47.5), 0, 140, linewidth=lw, color=color)
    three_arc = Arc((0, 0), 475, 475, theta1=22, theta2=158, linewidth=lw,
                    color=color)
    center_outer_arc = Arc((0, 422.5), 120, 120, theta1=180, theta2=0,
                           linewidth=lw, color=color)
    center_inner_arc = Arc((0, 422.5), 40, 40, theta1=180, theta2=0,
                           linewidth=lw, color=color)
    court_elements = [hoop, backboard, outer_box, inner_box, top_free_throw,
                      bottom_free_throw, restricted, corner_three_a,
                      corner_three_b, three_arc, center_outer_arc,
                      center_inner_arc]
    if outer_lines:
        outer_lines = Rectangle((-250, -47.5), 500, 470, linewidth=lw,
                                color=color, fill=False)
        court_elements.append(outer_lines)

    for element in court_elements:
        ax.add_patch(element)

    ax.set_xticklabels([])
    ax.set_yticklabels([])
    ax.set_xticks([])
    ax.set_yticks([])
    return ax

#for usage with shot_chart_bot
项目:nba_shot_charts    作者:Connor-R    | 项目源码 | 文件源码
def get_key_text(team_id, season_id, isCareer):

    text = ''

    games_text = get_metrics(team_id, season_id, isCareer, 'All', 'r.games')
    all_zone_plus = ("%.1f" % get_overall_zone_pct(team_id, season_id, isCareer))

    for _type in ('All', 'Above The Break 3', 'Corner 3', 'Mid-Range', 'In The Paint (Non-RA)', 'Restricted Area'):
        if _type == 'All':
            text += 'All Shots | %s Games | ' % games_text
        elif _type == 'Above The Break 3':
            text += '\n' + 'Arc 3 | '
        elif _type == 'In The Paint (Non-RA)':
            text += '\n' + 'Paint(Non-RA) | '
        elif _type == 'Restricted Area':
            text += '\n' + 'Restricted | '
        else:
            text += '\n' + _type + ' | '        

        atts = ("%.0f" %get_metrics(team_id, season_id, isCareer, _type, 'r.attempts'))
        makes = ("%.0f" %get_metrics(team_id, season_id, isCareer, _type, 'b.makes'))
        zone_pct = ("%.1f" % get_metrics(team_id, season_id, isCareer, _type, 'zone_pct*100'))
        zone_pct_plus = ("%.1f" % get_metrics(team_id, season_id, isCareer, _type, 'zone_pct_plus'))
        efg = ("%.1f" % get_metrics(team_id, season_id, isCareer, _type, 'efg*100'))
        efg_plus = ("%.1f" % get_metrics(team_id, season_id, isCareer, _type, 'efg_plus'))
        zone_efg_plus = ("%.1f" % get_metrics(team_id, season_id, isCareer, _type, 'zone_efg_plus'))
        paa = ("%.1f" % get_metrics(team_id, season_id, isCareer, _type, 'paa'))
        paa_game = ("%.1f" % get_metrics(team_id, season_id, isCareer, _type, 'paa_per_game'))

        if _type == 'All':
            text += str(makes) + ' for ' + str(atts)
            text += ' (' + str(all_zone_plus) + ' ShotSkill+ | '
            text += str(efg) + ' EFG% ('
            text += str(efg_plus) + ' EFG+ | '
            text += str(paa) + ' PAA)'
        else:
            text += str(makes) + '/' + str(atts) + ' | '
            text += str(zone_pct) + '% z% (' + str(zone_pct_plus) + ' z%+) | '
            text += str(zone_efg_plus) + ' zEFG+ ('
            text += str(efg_plus) + ' EFG+ | '
            text += str(paa) + ' PAA)'
    return text


#Getting the player's metrics for the given season
项目:nba_shot_charts    作者:Connor-R    | 项目源码 | 文件源码
def draw_court(ax=None, color='white', lw=2, outer_lines=False):
    from matplotlib.patches import Circle, Rectangle, Arc
    if ax is None:
        ax = plt.gca()
    hoop = Circle((0, 0), radius=7.5, linewidth=lw, color=color, fill=False)
    backboard = Rectangle((-30, -7.5), 60, -1, linewidth=lw, color=color)
    outer_box = Rectangle((-80, -47.5), 160, 190, linewidth=lw, color=color,
                          fill=False)
    inner_box = Rectangle((-60, -47.5), 120, 190, linewidth=lw, color=color,
                          fill=False)
    top_free_throw = Arc((0, 142.5), 120, 120, theta1=0, theta2=180,
                         linewidth=lw, color=color, fill=False)
    bottom_free_throw = Arc((0, 142.5), 120, 120, theta1=180, theta2=0,
                            linewidth=lw, color=color, linestyle='dashed')
    restricted = Arc((0, 0), 80, 80, theta1=0, theta2=180, linewidth=lw,
                     color=color)
    corner_three_a = Rectangle((-220, -50.0), 0, 140, linewidth=lw,
                               color=color)
    corner_three_b = Rectangle((219.75, -50.0), 0, 140, linewidth=lw, color=color)
    three_arc = Arc((0, 0), 475, 475, theta1=22, theta2=158, linewidth=lw,
                    color=color)
    center_outer_arc = Arc((0, 422.5), 120, 120, theta1=180, theta2=0,
                           linewidth=lw, color=color)
    center_inner_arc = Arc((0, 422.5), 40, 40, theta1=180, theta2=0,
                           linewidth=lw, color=color)
    court_elements = [hoop, backboard, outer_box, inner_box, top_free_throw,
                      bottom_free_throw, restricted, corner_three_a,
                      corner_three_b, three_arc, center_outer_arc,
                      center_inner_arc]
    if outer_lines:
        outer_lines = Rectangle((-250, -47.5), 500, 470, linewidth=lw,
                                color=color, fill=False)
        court_elements.append(outer_lines)

    for element in court_elements:
        ax.add_patch(element)

    ax.set_xticklabels([])
    ax.set_yticklabels([])
    ax.set_xticks([])
    ax.set_yticks([])
    return ax


#for usage with shot_chart_bot
项目:nba_shot_charts    作者:Connor-R    | 项目源码 | 文件源码
def draw_court(ax=None, color='white', lw=2, outer_lines=False):
    from matplotlib.patches import Circle, Rectangle, Arc
    if ax is None:
        ax = plt.gca()
    hoop = Circle((0, 0), radius=7.5, linewidth=lw, color=color, fill=False)
    backboard = Rectangle((-30, -7.5), 60, -1, linewidth=lw, color=color)
    outer_box = Rectangle((-80, -47.5), 160, 190, linewidth=lw, color=color,
                          fill=False)
    inner_box = Rectangle((-60, -47.5), 120, 190, linewidth=lw, color=color,
                          fill=False)
    top_free_throw = Arc((0, 142.5), 120, 120, theta1=0, theta2=180,
                         linewidth=lw, color=color, fill=False)
    bottom_free_throw = Arc((0, 142.5), 120, 120, theta1=180, theta2=0,
                            linewidth=lw, color=color, linestyle='dashed')
    restricted = Arc((0, 0), 80, 80, theta1=0, theta2=180, linewidth=lw,
                     color=color)
    corner_three_a = Rectangle((-220, -50.0), 0, 140, linewidth=lw,
                               color=color)
    corner_three_b = Rectangle((219.75, -50.0), 0, 140, linewidth=lw, color=color)
    three_arc = Arc((0, 0), 475, 475, theta1=22, theta2=158, linewidth=lw,
                    color=color)
    center_outer_arc = Arc((0, 422.5), 120, 120, theta1=180, theta2=0,
                           linewidth=lw, color=color)
    center_inner_arc = Arc((0, 422.5), 40, 40, theta1=180, theta2=0,
                           linewidth=lw, color=color)
    court_elements = [hoop, backboard, outer_box, inner_box, top_free_throw,
                      bottom_free_throw, restricted, corner_three_a,
                      corner_three_b, three_arc, center_outer_arc,
                      center_inner_arc]
    if outer_lines:
        outer_lines = Rectangle((-250, -47.5), 500, 470, linewidth=lw,
                                color=color, fill=False)
        court_elements.append(outer_lines)

    for element in court_elements:
        ax.add_patch(element)

    ax.set_xticklabels([])
    ax.set_yticklabels([])
    ax.set_xticks([])
    ax.set_yticks([])
    return ax
项目:nba_shot_charts    作者:Connor-R    | 项目源码 | 文件源码
def draw_court(ax=None, color='white', lw=2, outer_lines=False):
    from matplotlib.patches import Circle, Rectangle, Arc
    if ax is None:
        ax = plt.gca()
    hoop = Circle((0, 0), radius=7.5, linewidth=lw, color=color, fill=False)
    backboard = Rectangle((-30, -7.5), 60, -1, linewidth=lw, color=color)
    outer_box = Rectangle((-80, -47.5), 160, 190, linewidth=lw, color=color,
                          fill=False)
    inner_box = Rectangle((-60, -47.5), 120, 190, linewidth=lw, color=color,
                          fill=False)
    top_free_throw = Arc((0, 142.5), 120, 120, theta1=0, theta2=180,
                         linewidth=lw, color=color, fill=False)
    bottom_free_throw = Arc((0, 142.5), 120, 120, theta1=180, theta2=0,
                            linewidth=lw, color=color, linestyle='dashed')
    restricted = Arc((0, 0), 80, 80, theta1=0, theta2=180, linewidth=lw,
                     color=color)
    corner_three_a = Rectangle((-220, -50.0), 0, 140, linewidth=lw,
                               color=color)
    corner_three_b = Rectangle((219.75, -50.0), 0, 140, linewidth=lw, color=color)
    three_arc = Arc((0, 0), 475, 475, theta1=22, theta2=158, linewidth=lw,
                    color=color)
    center_outer_arc = Arc((0, 422.5), 120, 120, theta1=180, theta2=0,
                           linewidth=lw, color=color)
    center_inner_arc = Arc((0, 422.5), 40, 40, theta1=180, theta2=0,
                           linewidth=lw, color=color)
    court_elements = [hoop, backboard, outer_box, inner_box, top_free_throw,
                      bottom_free_throw, restricted, corner_three_a,
                      corner_three_b, three_arc, center_outer_arc,
                      center_inner_arc]
    if outer_lines:
        outer_lines = Rectangle((-250, -47.5), 500, 470, linewidth=lw,
                                color=color, fill=False)
        court_elements.append(outer_lines)

    for element in court_elements:
        ax.add_patch(element)

    ax.set_xticklabels([])
    ax.set_yticklabels([])
    ax.set_xticks([])
    ax.set_yticks([])
    return ax

#for usage with shot_chart_bot