示例#1
0
                                                   df_rayo_vallecano.end_y)

df_rayo_vallecano['x'] = rayo_x_std
df_rayo_vallecano['y'] = rayo_y_std
df_rayo_vallecano['end_x'] = xend_std
df_rayo_vallecano['end_y'] = yend_std

##############################################################################
# Now let's calculate the distance in meters for the passes in the game
# And compare to pass distance given in the StatsBomb dataframe
# The calculated distances are shorter as the pitch is smaller than the standard
# pitch dimensions (105 meters X 68 meters).

# filter passes
df_rayo_vallecano_pass = df_rayo_vallecano[df_rayo_vallecano.type_name ==
                                           'Pass'].copy()
# calculate the average pass length
custom_pitch = VerticalPitch(pitch_type='custom',
                             pitch_length=100,
                             pitch_width=65)
angle, distance = custom_pitch.calculate_angle_and_distance(
    df_rayo_vallecano_pass.x, df_rayo_vallecano_pass.y,
    df_rayo_vallecano_pass.end_x, df_rayo_vallecano_pass.end_y)
print('Calculated distance in meters')
print(pd.Series(distance).describe())
print('\nDistances in the StatsBomb data')
print((df_rayo_vallecano.pass_length *
       0.9144).describe())  # note converted from yards to meters

plt.show()  # If you are using a Jupyter notebook you do not need this line
示例#2
0
#
# Warning: The rotation angle is in degrees and assumes the original marker is pointing upwards ↑.
# If it's not you will have to modify the rotation degrees.
# Rotates the marker in degrees, clockwise. 0 degrees is facing the
# direction of play (left to right).
# In a horizontal pitch, 0 degrees is this way →, in a vertical pitch, 0 degrees is this way ↑
#
# We are going to plot pass data as an arrowhead marker with the
# arrow facing in the direction of the pass
# The marker size is going to relate to the pass distance,
# so larger markers mean the pass was longer.
pitch = Pitch()
fig, ax = pitch.draw(figsize=(14, 12))
angle, distance = pitch.calculate_angle_and_distance(df_pass_barca.x,
                                                     df_pass_barca.y,
                                                     df_pass_barca.end_x,
                                                     df_pass_barca.end_y,
                                                     standardized=False,
                                                     degrees=True)
sc = pitch.scatter(
    df_pass_barca.x,
    df_pass_barca.y,
    rotation_degrees=angle,
    c='#b94b75',  # color for scatter in hex format
    edgecolors='#383838',
    alpha=0.9,
    s=(distance / distance.max()) * 900,
    ax=ax,
    marker=arrowhead_marker)
title1 = fig.text(
    x=0.5,
    y=0.94,