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()
player_name team total
0 Aiko Jones University of Louisville 9
1 Alexa Hendricks University of Louisville 8
2 Alli Papesh University of Dayton 15
3 Amaya Tillman University of Louisville 8
4 Amelia Moore University of Dayton 9
5 Anna Stevenson University of Louisville 11
6 Bridget Doherty University of Dayton 3
7 Brooke Westbeld University of Dayton 6
8 Claire Chaussee University of Louisville 12
9 Emily Scott University of Louisville 10
10 Jamie Peterson University of Dayton 31
11 Jordan Albarran University of Dayton 1
12 Mel McHenry University of Louisville 23
13 Mikaylah Van Lanen University of Dayton 2
14 Molly Asmus University of Dayton 2
15 Olivia Dubay University of Dayton 13
16 Player2 player2 University of Louisville 10
17 Rachael Fara University of Dayton 10
18 Shannon Shields University of Louisville 2
19 Sierra Pla University of Dayton 5