The code demonstrates how to extract the coordinates of a team’s attack directions and displays the points of arrival and intensity through a heatmap.
Setup
import of the needed libraries
Code
from datavolley import read_dvimport datavolley.pycourt as pycourtimport datavolley.pycourt as half_pycourt import matplotlib.pyplot as pltimport pandas as pdimport numpy as npimport seaborn as snsimport warningswarnings.filterwarnings("ignore", "is_categorical_dtype")warnings.filterwarnings("ignore", "use_inf_as_na")
Data reading
In this case, we will use the sample data that PyDataVolley is built upon and extract the actions using the get_plays() method.
Code
dvf = read_dv.DataVolley()plays = dvf.get_plays()
Visualize the arrival of attacks
From the game actions we extract the information the x and y coordinates of the point of arrival of the attack. Our goal is to visualize the points where the ball arrives: where most of the play therefore takes place.
Using the same data we create the kernel density with seaborn and draw it on the field
Code
# heatmap of the end direction of attacksfig, ax = plt.subplots()pycourt.pycourt(ax)sns.kdeplot(x=coordinate_df['end_coordinate_x'], y=coordinate_df['end_coordinate_y'], ax=ax, cmap="YlOrRd", fill=True, alpha=0.5)plt.show()
Half a field
Among the functions available in pydatavolley is the ability to display half a court. Here we show how to use it
Code
# Creating the volleyball courtfig, ax = plt.subplots()pycourt.half_pycourt(ax)# Creating the heatmapsns.kdeplot(x=coordinate_df['end_coordinate_x'], y=coordinate_df['end_coordinate_y'], ax=ax, cmap="YlOrRd", fill=True, alpha=0.5)plt.show()