示例#1
0
# setup pitch
pitch = VerticalPitch(pitch_type='statsbomb',
                      line_zorder=2,
                      pitch_color='#22312b',
                      line_color='white')
# 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,
示例#2
0
    axes[i, 1].axis('off')
    axes[i, 0].imshow(gradient, cmap=cmap)
    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)