df_false9.head() ############################################################################## # Plotting Messi's first game as a False-9 pitch = Pitch(pitch_type='statsbomb', pitch_color='grass', stripe=True) fig, ax = pitch.draw(figsize=(16, 11)) # plotting ax.set_title('The first Game Messi played in the false 9 role', fontsize=30, pad=20) # plot the kernel density estimation pitch.kdeplot(df_false9.x, df_false9.y, ax=ax, cmap='plasma', linewidths=3) # annotate pitch.annotate('6-2 thrashing \nof Real Madrid', (25, 10), color='white', fontsize=25, ha='center', va='center', ax=ax) pitch.annotate('more events', (70, 30), (20, 30), ax=ax, color='white', ha='center', va='center', fontsize=20, arrowprops=dict(facecolor='white', edgecolor='None'))
############################################################################## # Kdeplot shot map with kdeplot on the marginal axes # -------------------------------------------------- fig, axes, _, _ = pitch.jointgrid( figheight=10, left=None, bottom=0.075, grid_height=0.8, # plot without endnote/ title axes title_height=0, endnote_height=0) # increase number of levels for a smoother looking heatmap kde1 = pitch.kdeplot(df_team1.x, df_team1.y, ax=axes[0], cmap='Reds', levels=75, shade=True) kde2 = pitch.kdeplot(df_team2.x, df_team2.y, ax=axes[0], cmap='Blues', levels=75, shade=True) # kdeplot on marginal axes team1_hist_y = sns.kdeplot(y=df_team1.y, ax=axes[1], color=red, shade=True) team1_hist_x = sns.kdeplot(x=df_team1.x, ax=axes[2], color=red, shade=True) team2_hist_x = sns.kdeplot(x=df_team2.x, ax=axes[2], color=blue, shade=True) team2_hist_y = sns.kdeplot(y=df_team2.y, ax=axes[3], color=blue, shade=True) txt1 = axes[0].text(x=15, y=70,
# add information for subsitutions on/off and arrows if not np.isnan(lineup_team.iloc[idx].off): ax.text(116, -10, str(lineup_team.iloc[idx].off.astype(int)), fontsize=20, fontproperties=fm_scada.prop, ha='center', va='center') ax.annotate('', (120, -2), (112, -2), arrowprops=red_arrow) if not np.isnan(lineup_team.iloc[idx].on): ax.text(104, -10, str(lineup_team.iloc[idx].on.astype(int)), fontsize=20, fontproperties=fm_scada.prop, ha='center', va='center') ax.annotate('', (108, -2), (100, -2), arrowprops=green_arrow) # plot on the last Pass Map # (note ax=ax as we have cycled through to the last axes in the loop) pitch.kdeplot(x=pass_receipts.x, y=pass_receipts.y, ax=ax, cmap=cmr.lavender, levels=100, thresh=0, shade=True) ax.text(0, -5, f'{team}: Pass Receipt Heatmap', ha='left', va='center', fontsize=20, fontproperties=fm_scada.prop) # remove unused axes (if any) for ax in axs['pitch'].flat[11 + num_sub:-1]: ax.remove() # endnote text axs['endnote'].text(0, 0.5, 'The format is copied from @DymondFormation', fontsize=20, fontproperties=fm_scada.prop, va='center', ha='left') # to get the left position to align with the pitches I plotted it once with a random # left position (e.g. 0.5) and then used the following code # bbox_sb = ax_sb_logo.get_position() # bbox_endnote = axs['endnote'].get_position()
# add information for subsitutions on/off and arrows if not np.isnan(lineup_team.iloc[idx].off): ax.text(116, -10, str(lineup_team.iloc[idx].off.astype(int)), fontsize=20, fontproperties=fm_scada.prop, ha='center', va='center') ax.annotate('', (120, -2), (112, -2), arrowprops=red_arrow) if not np.isnan(lineup_team.iloc[idx].on): ax.text(104, -10, str(lineup_team.iloc[idx].on.astype(int)), fontsize=20, fontproperties=fm_scada.prop, ha='center', va='center') ax.annotate('', (108, -2), (100, -2), arrowprops=green_arrow) # plot on the last Pass Map # (note ax=ax as we have cycled through to the last axes in the loop) pitch.kdeplot(x=passes_excl_set.x, y=passes_excl_set.y, ax=ax, cmap=cmr.lavender, levels=100, thresh=0, shade=True) ax.text(0, -5, f'{team}: Open Play Pass Heatmap', ha='left', va='center', fontsize=20, fontproperties=fm_scada.prop) # remove unused axes (if any) for ax in axs.flat[11 + num_sub:-1]: ax.remove() # endnote text ax_endnote.text(0, 0.5, 'The format is copied from @DymondFormation', fontsize=20, fontproperties=fm_scada.prop, va='center', ha='left') # to get the left position to align with the pitches I plotted it once with a random # left position (e.g. 0.5) and then used the following code # bbox_sb = ax_sb_logo.get_position() # bbox_endnote = ax_endnote.get_position()