############################################################################## # Hexbin shot map with kdeplot marginal axes # ------------------------------------------ fig, axes, _, _ = pitch.jointgrid( figheight=10, left=None, bottom=0.075, grid_height=0.8, # plot without endnote/ title axes endnote_height=0, title_height=0) # plot the hexbins hex1 = pitch.hexbin(df_team1.x, df_team1.y, ax=axes[0], edgecolors=pitch.line_color, cmap='Reds') hex2 = pitch.hexbin(df_team2.x, df_team2.y, ax=axes[0], edgecolors=pitch.line_color, cmap='Blues') # normalize the values so the colors depend on the minimum/ value for both teams # this ensures that darker colors mean more shots relative to both teams vmin = min(hex1.get_array().min(), hex2.get_array().min()) vmax = max(hex1.get_array().max(), hex2.get_array().max()) hex1.set_clim(vmin=vmin, vmax=vmax) hex2.set_clim(vmin=vmin, vmax=vmax) # plot kdeplots on the marginals team1_hist_y = sns.kdeplot(y=df_team1.y, ax=axes[1], color=red, shade=True)
kwargs = { 'related_event_df': False, 'shot_freeze_frame_df': False, 'tactics_lineup_df': False, 'warn': False } df_false9 = read_event(f'{EVENT_SLUG}/69249.json', **kwargs)['event'] df_before_false9 = read_event(f'{EVENT_SLUG}/69251.json', **kwargs)['event'] # filter messi's actions (starting positions) df_false9 = df_false9.loc[df_false9.player_id == 5503, ['x', 'y']] df_before_false9 = df_before_false9.loc[df_before_false9.player_id == 5503, ['x', 'y']] ############################################################################## # plotting pitch = Pitch(pitch_type='statsbomb', pitch_color='#22312b', stripe=False, line_zorder=2) fig, ax = pitch.draw( figsize=(16, 9), nrows=1, ncols=2, ) pitch.hexbin(df_before_false9.x, df_before_false9.y, ax=ax[0], cmap='Blues') pitch.hexbin(df_false9.x, df_false9.y, ax=ax[1], cmap='Blues') TITLE_STR1 = 'Messi in the game directly before \n playing in the false 9 role' TITLE_STR2 = 'The first Game Messi \nplayed in the false 9 role' title1 = ax[0].set_title(TITLE_STR1, fontsize=25, pad=20) title2 = ax[1].set_title(TITLE_STR2, fontsize=25, pad=20)