Beispiel #1
0
        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()
# left = bbox_endnote.x1 - bbox_sb.width
ax_sb_logo = add_image(sb_logo, fig, left=0.7970,
                       # set the bottom and height to align with the endnote
                       bottom=axs['endnote'].get_position().y0,
                       height=axs['endnote'].get_position().height)

# title text
axs['title'].text(0.5, 0.65, f'{team1} Pass Maps vs {team2}', fontsize=40,
                  fontproperties=fm_scada.prop, va='center', ha='center')
SUB_TEXT = ('Player Pass Maps: exclude throw-ins only\n'
            'Team heatmap: includes all attempted pass receipts')
axs['title'].text(0.5, 0.35, SUB_TEXT, fontsize=20,
                  fontproperties=fm_scada.prop, va='center', ha='center')
# plot logos (same height as the title_ax)
# set the barca logo to align with the left/bottom of the title axes
ax_barca_logo = add_image(barca_logo, fig,
                          left=axs['title'].get_position().x0,
                          bottom=axs['title'].get_position().y0,
                          height=axs['title'].get_position().height)
Beispiel #2
0
IMAGE_URL = 'https://upload.wikimedia.org/wikipedia/commons/b/b8/Messi_vs_Nigeria_2018.jpg'
image = Image.open(urlopen(IMAGE_URL))

##############################################################################
# Plotting an image over a pitch
# ##############################
#
# To plot images you use ``Axes.imshow()`` in matplotlib.
# We are going to draw a pitch and then overlay ontop an image of Messi on a new axis.

# draw the pitch
pitch = Pitch(line_zorder=2)
fig, ax = pitch.draw(figsize=(16, 9), tight_layout=False)

# add an image
ax_image = add_image(image, fig, left=0.55, bottom=0.2, width=0.2,
                     alpha=0.9, interpolation='hanning')

##############################################################################
# Photo from: https://en.wikipedia.org/wiki/Lionel_Messi#/media/File:Messi_vs_Nigeria_2018.jpg;
# License: https://creativecommons.org/licenses/by-sa/3.0/;
# Creator: Кирилл Венедиктов

##############################################################################
# More control over the images and axis
# #####################################
#
# For more control over where the images are placed,
# you can create a blank figure with ``plt.figure()``
# and then use ``Figure.add_axes()`` to add seperate axes for each of the plot elements.

# setup a blank figure
fig.patches.extend([
    plt.Rectangle((0.31, 0.9225),
                  0.025,
                  0.021,
                  fill=True,
                  color="#1a78cf",
                  transform=fig.transFigure,
                  figure=fig),
    plt.Rectangle((0.462, 0.9225),
                  0.025,
                  0.021,
                  fill=True,
                  color="#ff9300",
                  transform=fig.transFigure,
                  figure=fig),
    plt.Rectangle((0.632, 0.9225),
                  0.025,
                  0.021,
                  fill=True,
                  color="#d70232",
                  transform=fig.transFigure,
                  figure=fig),
])

# add image
ax_image = add_image(
    fdj_cropped, fig, left=0.4478, bottom=0.4315, width=0.13,
    height=0.127)  # these values might differ when you are plotting

plt.show()
Beispiel #4
0
                  va='center',
                  ha='center',
                  fontproperties=robotto_regular.prop,
                  fontsize=30)
axs['title'].text(0.5,
                  0.25,
                  "First game as a false nine",
                  color='#000009',
                  va='center',
                  ha='center',
                  fontproperties=robotto_regular.prop,
                  fontsize=20)
ax_sb_logo = add_image(
    sb_logo,
    fig,
    # set the left, bottom and height to align with the endnote
    left=axs['endnote'].get_position().x0,
    bottom=axs['endnote'].get_position().y0,
    height=axs['endnote'].get_position().height)

##############################################################################
# Plot Messi's actions in the matches before and after becoming a false-9.
# We will use mplsoccer's grid function, which is a convenient way to plot a grid
# of pitches with a title and endnote axes.

fig, axs = pitch.grid(ncols=2, axis=False)
hexmap_before = pitch.hexbin(df_before_false9.x,
                             df_before_false9.y,
                             ax=axs['pitch'][0],
                             edgecolors='#f4f4f4',
                             gridsize=(8, 8),
Beispiel #5
0
         highlight_textprops=[{
             "color": 'crimson'
         }, {
             "color": 'skyblue'
         }, {
             "color": 'gold'
         }],
         size=25,
         fig=fig,
         fontproperties=font_bold.prop)

# add image
fig = add_image(
    epl,
    fig,  # figure
    0.02,
    0.9,  # left and bottom dimensions
    0.08,
    0.08  # height and width values
)

# if space is left in the plot use this
plt.tight_layout(pad=0.5)

##############################################################################
# Flip The y-axis
# ----------------------------
# If you want to plot positions from the bottom, i.e. the 1st position will
# be at the bottom and the 20th position will be at the top. You can do it easily.
# You just have to pass ``upside_down=True`` inside ``plot`` function.

# instantiate object
Beispiel #6
0
    for label in annotate:
        label.set_path_effects([
            path_effects.Stroke(linewidth=3, foreground='black'),
            path_effects.Normal()
        ])
axes = axes.reshape(4, 5)
cbar = fig.colorbar(heatmap, ax=axes[:, 4], shrink=0.85)
cbar.ax.tick_params(labelsize=20)
# if its the Bundesliga remove the two spare pitches
if len(teams) == 18:
    for ax in axes[-1, 3:]:
        ax.remove()
# load the StatsBomb logo and add it to the plot
LOGO_URL = 'https://raw.githubusercontent.com/statsbomb/open-data/master/img/statsbomb-logo.jpg'
sb_logo = Image.open(urlopen(LOGO_URL))
add_image(sb_logo, fig, left=0.9, bottom=0.975, width=0.1)
title = fig.suptitle('Pressure events %, Bundesliga, 2019/20', fontsize=20)

##############################################################################
# Plot the percentage point difference

# Calculate the percentage point difference from the league average
df[pressure_cols] = df[pressure_cols].values - df_total.values

# plot the percentage point difference
pitch = Pitch(line_zorder=2, line_color='black')
fig, axes = pitch.draw(figsize=(16, 9),
                       ncols=5,
                       nrows=4,
                       tight_layout=False,
                       constrained_layout=True)
Beispiel #7
0
        ax.remove()

# add cbar axes
cbar_bottom = axs['pitch'][-1, 0].get_position().y0
cbar_left = axs['pitch'][0, -1].get_position().x1 + 0.01
ax_cbar = fig.add_axes((cbar_left, cbar_bottom, CBAR_WIDTH,
                        # take a little bit off the height because of padding
                        GRID_HEIGHT - 0.036))
cbar = plt.colorbar(heatmap, cax=ax_cbar)
for label in cbar.ax.get_yticklabels():
    label.set_fontproperties(fm.prop)
    label.set_fontsize(50)

# title and endnote
add_image(sb_logo, fig,
          left=axs['endnote'].get_position().x0,
          bottom=axs['endnote'].get_position().y0,
          height=axs['endnote'].get_position().height)
title = axs['title'].text(0.5, 0.5, 'Pressure events %, Bundesliga, 2019/20',
                          ha='center', va='center', fontsize=70)

##############################################################################
# Plot the percentage point difference

# Calculate the percentage point difference from the league average
df[pressure_cols] = df[pressure_cols].values - df_total.values

GRID_HEIGHT = 0.76
fig, axs = pitch.grid(nrows=4, ncols=5, figheight=20,
                      # leaves some space on the right hand side for the colorbar
                      grid_width=0.88, left=0.025,
                      endnote_height=0.06, endnote_space=0,