Example #1
0
    figsize=(16, 9),
    ncols=3,
    nrows=1,
)
# heatmap specified by (nx, ny) for horizontal pitch
bins = [(6, 5), (1, 5), (6, 1)]
for i, bin_dimension in enumerate(bins):
    bin_statistic = pitch.bin_statistic(df.x,
                                        df.y,
                                        statistic='count',
                                        bins=bin_dimension)
    # draw
    pitch.heatmap(bin_statistic,
                  ax=ax[i],
                  cmap='coolwarm',
                  edgecolors='#22312b')
    pitch.scatter(df.x, df.y, c='white', s=2, ax=ax[i])
    # replace raw counts with percentages and add percentage sign
    # (note immutable named tuple so used _replace)
    bin_statistic['statistic'] = ((pd.DataFrame(
        (bin_statistic['statistic'] / bin_statistic['statistic'].sum()
         ))).applymap(lambda x: '{:.0%}'.format(x)).values)
    pitch.label_heatmap(bin_statistic,
                        color='white',
                        fontsize=18,
                        ax=ax[i],
                        ha='center',
                        va='bottom')
TITLE_STR = 'Location of pressure events - 3 home games for Chelsea FC Women'
title = fig.suptitle(TITLE_STR, x=0.5, y=0.98, fontsize=30)
Example #2
0
# draw
fig, ax = pitch.draw(figsize=(4.125, 6))
bin_statistic = pitch.bin_statistic_positional(df.x,
                                               df.y,
                                               statistic='count',
                                               positional='full',
                                               normalize=True)
pitch.heatmap_positional(bin_statistic,
                         ax=ax,
                         cmap='coolwarm',
                         edgecolors='#22312b')
pitch.scatter(df.x, df.y, c='white', s=2, ax=ax)
labels = pitch.label_heatmap(bin_statistic,
                             color='#f4edf0',
                             fontsize=18,
                             ax=ax,
                             ha='center',
                             va='center',
                             str_format='{:.0%}',
                             path_effects=path_eff)

##############################################################################
# Plot the chart again with a title
# ---------------------------------
# We will use mplsoccer's grid function to plot a pitch with a title and endnote axes.
pitch = VerticalPitch(pitch_type='statsbomb',
                      line_zorder=2,
                      pitch_color='#1e4259')
fig, axs = pitch.grid(
    endnote_height=0.03,
    endnote_space=0,
    title_height=0.08,