tight_layout=True) # Now lets plot the shots for i, shot in shots.iterrows(): x = shot['location'][0] y = shot['location'][1] goal = shot['shot_outcome_name'] == 'Goal' team_name = shot['team_name'] circleSize = 2 #circleSize=np.sqrt(shot['shot_statsbomb_xg'])*12 if (team_name == team1): if goal: # shotCircle=plt.Circle((x,pitchWidthY-y),circleSize,color="red") shotCircle = pitch.scatter(x, pitchWidthY - y, marker='football', ax=ax) # plt.text((x+1),pitchWidthY-y+1,shot['player_name']) else: shotCircle = pitch.scatter(x, pitchWidthY - y, ax=ax) # shotCircle=plt.Circle((x,pitchWidthY-y),circleSize,color="red") elif (team_name == team2): if goal: shotCircle = pitch.scatter(pitchLengthX - x, y, marker='football', ax=ax) # shotCircle=plt.Circle((pitchLengthX-x,y),circleSize,color="blue") # plt.text((pitchLengthX-x+1),y+1,shot['player_name']) else: shotCircle = pitch.scatter(pitchLengthX - x, y, ax=ax)
) fig, ax = pitch.draw(figsize=(16, 11), constrained_layout=True, tight_layout=False) pass_lines = pitch.lines(passes_between.x, passes_between.y, passes_between.x_end, passes_between.y_end, lw=passes_between.width, color=color, zorder=1, ax=ax) pass_nodes = pitch.scatter(average_locs_and_count.x, average_locs_and_count.y, s=average_locs_and_count.marker_size, color='red', edgecolors='black', linewidth=1, alpha=1, ax=ax) for index, row in average_locs_and_count.iterrows(): pitch.annotate(row.name, xy=(row.x, row.y), c='white', va='center', ha='center', size=16, weight='bold', ax=ax) title = ax.set_title("{} {} Formation vs {}".format(TEAM, FORMATION, OPPONENT), size=28, y=0.97,
fig, axes, _, _ = pitch.jointgrid( figheight=10, # the figure is 10 inches high left=None, # joint grid center-aligned bottom=0.075, # grid starts 7.5% in from the bottom of the figure marginal=0.1, # marginal axes heights are 10% of grid height space=0, # 0% of the grid height reserved for space between axes grid_width=0.9, # the grid width takes up 90% of the figure width title_height=0, # plot without a title axes endnote_height=0, # plot without an endnote axes grid_height=0.8) # grid takes up 80% of the figure height # we plot a usual scatter plot but the scatter size is based on expected goals # note that the size is the expected goals * 700 # so any shots with an expected goals = 1 would take a size of 700 (points**2) sc_team1 = pitch.scatter(df_team1.x, df_team1.y, s=df_team1.shot_statsbomb_xg * 700, ec='black', color='#ba495c', ax=axes[0]) sc_team2 = pitch.scatter(df_team2.x, df_team2.y, s=df_team1.shot_statsbomb_xg * 700, ec='black', color='#697cd4', ax=axes[0]) # (step) histograms on each of the left, top, and right marginal axes team1_hist_y = sns.histplot(y=df_team1.y, ax=axes[1], element='step', color='#ba495c') team1_hist_x = sns.histplot(x=df_team1.x, ax=axes[2],
df_pass.y, df_pass.end_x, df_pass.end_y, lw=10, transparent=True, comet=True, cmap='jet', label='pass leading to shot', ax=axs['pitch']) # Plot the goals pitch.scatter(df_pass[mask_goal].end_x, df_pass[mask_goal].end_y, s=700, marker='football', edgecolors='black', c='white', zorder=2, label='goal', ax=axs['pitch']) pitch.scatter(df_pass[~mask_goal].end_x, df_pass[~mask_goal].end_y, edgecolors='white', c='#22312b', s=700, zorder=2, label='shot', ax=axs['pitch']) # endnote and title axs['endnote'].text(1,
import matplotlib.pyplot as plt # read data df = read_event(f'{EVENT_SLUG}/7478.json', related_event_df=False, shot_freeze_frame_df=False, tactics_lineup_df=False)['event'] ############################################################################## # Filter passes by Jodie Taylor df = df[(df.player_name == 'Jodie Taylor') & (df.type_name == 'Pass')].copy() ############################################################################## # Plotting pitch = Pitch() fig, ax = pitch.draw(figsize=(8, 6)) hull = pitch.convexhull(df.x, df.y) poly = pitch.polygon(hull, ax=ax, edgecolor='cornflowerblue', facecolor='cornflowerblue', alpha=0.3) scatter = pitch.scatter(df.x, df.y, ax=ax, edgecolor='black', facecolor='cornflowerblue') plt.show( ) # if you are not using a Jupyter notebook this is necessary to show the plot