Exemplo n.º 1
0
# draw
fig, ax = pitch.draw(
    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)
Exemplo n.º 2
0
    axes[i, 1].text(0,
                    0.5,
                    cmap.name,
                    va='center',
                    fontsize=20,
                    fontproperties=fm.prop)

##############################################################################
# Cyan colormap heatmap
pitch = VerticalPitch(line_color='#cfcfcf',
                      line_zorder=2,
                      pitch_color='#122c3d')
fig, ax = pitch.draw(figsize=(4.4, 6.4))
bs = pitch.bin_statistic(df.x, df.y, bins=(12, 8))
heatmap = pitch.heatmap(bs,
                        edgecolors='#122c3d',
                        ax=ax,
                        cmap=pearl_earring_cmap)

##############################################################################
# Cyan colormap hexbin
fig, ax = pitch.draw()
hexmap = pitch.hexbin(df.x,
                      df.y,
                      ax=ax,
                      edgecolors='#122c3d',
                      gridsize=(8, 8),
                      cmap=pearl_earring_cmap)

##############################################################################
# Cyan colormap kdeplot
pitch = VerticalPitch(line_color='#cfcfcf',