from statsbombpy import sb
from mplsoccer.pitch import Pitch
import mplsoccer as mpls
import statsbombpy
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from mplEasyAnimate import animation
sb.competitions().tail()
credentials were not supplied. open data access only
competition_id | season_id | country_name | competition_name | competition_gender | competition_youth | competition_international | season_name | match_updated | match_updated_360 | match_available_360 | match_available | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
35 | 11 | 37 | Spain | La Liga | male | False | False | 2004/2005 | 2020-07-29T05:00 | 2021-06-13T16:17:31.694 | None | 2020-07-29T05:00 |
36 | 49 | 3 | United States of America | NWSL | female | False | False | 2018 | 2021-11-06T05:53:29.435016 | 2021-06-13T16:17:31.694 | None | 2021-11-06T05:53:29.435016 |
37 | 2 | 44 | England | Premier League | male | False | False | 2003/2004 | 2021-11-14T22:29:00.646120 | 2021-06-13T16:17:31.694 | None | 2021-11-14T22:29:00.646120 |
38 | 55 | 43 | Europe | UEFA Euro | male | False | True | 2020 | 2021-11-11T14:00:16.105809 | 2021-11-11T13:54:37.507376 | 2021-11-11T13:54:37.507376 | 2021-11-11T14:00:16.105809 |
39 | 72 | 30 | International | Women's World Cup | female | False | True | 2019 | 2020-07-29T05:00 | 2021-06-13T16:17:31.694 | None | 2020-07-29T05:00 |
sb.matches(competition_id=55, season_id=43)
credentials were not supplied. open data access only
match_id | match_date | kick_off | competition | season | home_team | away_team | home_score | away_score | match_status | match_status_360 | last_updated | last_updated_360 | match_week | competition_stage | stadium | referee | data_version | shot_fidelity_version | xy_fidelity_version | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 3788753 | 2021-06-16 | 15:00:00.000 | Europe - UEFA Euro | 2020 | Finland | Russia | 0 | 1 | available | available | 2021-11-11T14:00:16.105809 | 2021-09-22T16:39:05.697512 | 2 | Group Stage | Saint-Petersburg Stadium | Danny Desmond Makkelie | 1.1.0 | 2 | 2 |
1 | 3788765 | 2021-06-20 | 18:00:00.000 | Europe - UEFA Euro | 2020 | Switzerland | Turkey | 3 | 1 | available | available | 2021-08-02T14:58:49.057 | 2021-11-11T13:54:37.507376 | 3 | Group Stage | Bakı Olimpiya Stadionu | Slavko Vinčić | 1.1.0 | 2 | 2 |
2 | 3795107 | 2021-07-02 | 21:00:00.000 | Europe - UEFA Euro | 2020 | Belgium | Italy | 1 | 2 | available | available | 2021-07-19T12:41:55.898 | 2021-09-23T00:02:51.495862 | 5 | Quarter-finals | Allianz Arena (München) | Slavko Vinčić | 1.1.0 | 2 | 2 |
3 | 3795221 | 2021-07-07 | 21:00:00.000 | Europe - UEFA Euro | 2020 | England | Denmark | 2 | 1 | available | available | 2021-07-09T12:38:23.437 | 2021-09-22T22:33:37.494366 | 6 | Semi-finals | Wembley Stadium (London) | Danny Desmond Makkelie | 1.1.0 | 2 | 2 |
4 | 3795506 | 2021-07-11 | 21:00:00.000 | Europe - UEFA Euro | 2020 | Italy | England | 1 | 1 | available | available | 2021-07-12T12:27:50.647 | 2021-09-22T22:40:31.690550 | 7 | Final | Wembley Stadium (London) | Björn Kuipers | 1.1.0 | 2 | 2 |
5 | 3794688 | 2021-06-29 | 18:00:00.000 | Europe - UEFA Euro | 2020 | England | Germany | 2 | 0 | available | available | 2021-08-21T19:00:29.036 | 2021-09-22T23:46:25.457149 | 4 | Round of 16 | Wembley Stadium (London) | Danny Desmond Makkelie | 1.1.0 | 2 | 2 |
6 | 3794692 | 2021-06-29 | 21:00:00.000 | Europe - UEFA Euro | 2020 | Sweden | Ukraine | 1 | 2 | available | available | 2021-10-09T14:22:25.560075 | 2021-09-22T23:38:19.483199 | 4 | Round of 16 | Hampden Park | Daniele Orsato | 1.1.0 | 2 | 2 |
7 | 3794686 | 2021-06-28 | 18:00:00.000 | Europe - UEFA Euro | 2020 | Croatia | Spain | 3 | 5 | available | available | 2021-06-29T12:51:11.507 | 2021-09-22T23:30:10.428563 | 4 | Round of 16 | Nya Parken | Cüneyt Çakιr | 1.1.0 | 2 | 2 |
8 | 3794687 | 2021-06-27 | 21:00:00.000 | Europe - UEFA Euro | 2020 | Belgium | Portugal | 1 | 0 | available | available | 2021-07-05T13:37:21.633 | 2021-09-22T16:40:48.020474 | 4 | Round of 16 | Estadio Olímpico de Sevilla (Sevilla) | Felix Brych | 1.1.0 | 2 | 2 |
9 | 3794685 | 2021-06-26 | 21:00:00.000 | Europe - UEFA Euro | 2020 | Italy | Austria | 2 | 1 | available | available | 2021-06-27T13:56:22.030 | 2021-09-22T16:40:41.310001 | 4 | Round of 16 | Wembley Stadium (London) | Anthony Taylor | 1.1.0 | 2 | 2 |
10 | 3788774 | 2021-06-23 | 21:00:00.000 | Europe - UEFA Euro | 2020 | Germany | Hungary | 2 | 2 | available | available | 2021-09-16T22:37:38.476197 | 2021-09-22T16:40:32.702910 | 3 | Group Stage | Allianz Arena (München) | Sergey Karasev | 1.1.0 | 2 | 2 |
11 | 3788771 | 2021-06-22 | 21:00:00.000 | Europe - UEFA Euro | 2020 | Croatia | Scotland | 3 | 1 | available | available | 2021-06-23T13:41:52.672 | 2021-09-22T16:40:26.078582 | 3 | Group Stage | Hampden Park | Fernando Andrés Rapallini | 1.1.0 | 2 | 2 |
12 | 3788772 | 2021-06-22 | 21:00:00.000 | Europe - UEFA Euro | 2020 | Czech Republic | England | 0 | 1 | available | available | 2021-06-23T13:36:16.640 | 2021-09-22T16:40:22.128510 | 3 | Group Stage | Wembley Stadium (London) | Artur Manuel Ribeiro Soares Dias | 1.1.0 | 2 | 2 |
13 | 3788768 | 2021-06-21 | 21:00:00.000 | Europe - UEFA Euro | 2020 | Finland | Belgium | 0 | 2 | available | available | 2021-06-22T13:47:34.925 | 2021-09-22T16:40:14.297313 | 3 | Group Stage | Saint-Petersburg Stadium | Felix Brych | 1.1.0 | 2 | 2 |
14 | 3788767 | 2021-06-21 | 18:00:00.000 | Europe - UEFA Euro | 2020 | Ukraine | Austria | 0 | 1 | available | available | 2021-06-27T13:34:43.104 | 2021-09-22T16:40:10.486010 | 3 | Group Stage | Arena Naţională (Bucureşti) | Cüneyt Çakιr | 1.1.0 | 2 | 2 |
15 | 3788763 | 2021-06-19 | 15:00:00.000 | Europe - UEFA Euro | 2020 | Hungary | France | 1 | 1 | available | available | 2021-06-21T13:08:32.522 | 2021-09-22T16:40:01.281735 | 2 | Group Stage | Puskás Aréna | Michael Oliver | 1.1.0 | 2 | 2 |
16 | 3788759 | 2021-06-18 | 21:00:00.000 | Europe - UEFA Euro | 2020 | England | Scotland | 0 | 0 | available | available | 2021-07-14T12:59:48.602 | 2021-09-22T16:39:45.108967 | 2 | Group Stage | Wembley Stadium (London) | Antonio Miguel Mateu Lahoz | 1.1.0 | 2 | 2 |
17 | 3788758 | 2021-06-17 | 15:00:00.000 | Europe - UEFA Euro | 2020 | Ukraine | North Macedonia | 2 | 1 | available | available | 2021-06-19T12:31:42.085 | 2021-09-22T16:39:24.057039 | 2 | Group Stage | Arena Naţională (Bucureşti) | Fernando Andrés Rapallini | 1.1.0 | 2 | 2 |
18 | 3788757 | 2021-06-17 | 18:00:00.000 | Europe - UEFA Euro | 2020 | Denmark | Belgium | 1 | 2 | available | available | 2021-07-24T16:17:22.251 | 2021-09-22T16:39:19.238605 | 2 | Group Stage | Nya Parken | Björn Kuipers | 1.1.0 | 2 | 2 |
19 | 3788745 | 2021-06-13 | 15:00:00.000 | Europe - UEFA Euro | 2020 | England | Croatia | 1 | 0 | available | available | 2021-07-19T16:25:28.955 | 2021-09-22T16:38:34.452309 | 1 | Group Stage | Wembley Stadium (London) | Daniele Orsato | 1.1.0 | 2 | 2 |
20 | 3788746 | 2021-06-13 | 21:00:00.000 | Europe - UEFA Euro | 2020 | Netherlands | Ukraine | 3 | 2 | available | available | 2021-06-14T12:58:15.673 | 2021-09-22T16:38:23.709230 | 1 | Group Stage | Johan Cruijff Arena (Amsterdam) | Felix Brych | 1.1.0 | 2 | 2 |
21 | 3794691 | 2021-06-28 | 21:00:00.000 | Europe - UEFA Euro | 2020 | France | Switzerland | 3 | 3 | available | available | 2021-06-29T04:56:23.547 | 2021-09-22T16:40:50.520965 | 4 | Round of 16 | Arena Naţională (Bucureşti) | Fernando Andrés Rapallini | 1.1.0 | 2 | 2 |
22 | 3794690 | 2021-06-27 | 18:00:00.000 | Europe - UEFA Euro | 2020 | Netherlands | Czech Republic | 0 | 2 | available | available | 2021-06-28T12:45:34.881 | 2021-09-22T16:40:45.809899 | 4 | Round of 16 | Puskás Aréna | Sergey Karasev | 1.1.0 | 2 | 2 |
23 | 3794689 | 2021-06-26 | 18:00:00.000 | Europe - UEFA Euro | 2020 | Wales | Denmark | 0 | 4 | available | available | 2021-08-10T14:33:01.831 | 2021-09-22T16:40:43.833676 | 4 | Round of 16 | Johan Cruijff Arena (Amsterdam) | Daniel Siebert | 1.1.0 | 2 | 2 |
24 | 3788769 | 2021-06-21 | 21:00:00.000 | Europe - UEFA Euro | 2020 | Russia | Denmark | 1 | 4 | available | available | 2021-07-15T14:05:30.270 | 2021-09-22T16:40:07.193964 | 3 | Group Stage | Nya Parken | Clément Turpin | 1.1.0 | 2 | 2 |
25 | 3788761 | 2021-06-18 | 15:00:00.000 | Europe - UEFA Euro | 2020 | Sweden | Slovakia | 1 | 0 | available | available | 2021-06-20T13:02:21.442 | 2021-09-22T16:39:35.442778 | 2 | Group Stage | Saint-Petersburg Stadium | Daniel Siebert | 1.1.0 | 2 | 2 |
26 | 3788764 | 2021-06-19 | 18:00:00.000 | Europe - UEFA Euro | 2020 | Portugal | Germany | 2 | 4 | available | available | 2021-06-20T13:10:40.911 | 2021-09-22T16:39:51.835300 | 2 | Group Stage | Allianz Arena (München) | Anthony Taylor | 1.1.0 | 2 | 2 |
27 | 3788766 | 2021-06-20 | 18:00:00.000 | Europe - UEFA Euro | 2020 | Italy | Wales | 1 | 0 | available | available | 2021-06-21T20:35:17.912 | 2021-09-22T16:40:03.894292 | 3 | Group Stage | Stadio Olimpico (Roma) | Ovidiu Alin Hațegan | 1.1.0 | 2 | 2 |
28 | 3788754 | 2021-06-16 | 21:00:00.000 | Europe - UEFA Euro | 2020 | Italy | Switzerland | 3 | 0 | available | available | 2021-06-17T13:24:15.990 | 2021-09-22T16:39:11.835841 | 2 | Group Stage | Stadio Olimpico (Roma) | Sergey Karasev | 1.1.0 | 2 | 2 |
29 | 3788755 | 2021-06-16 | 18:00:00.000 | Europe - UEFA Euro | 2020 | Turkey | Wales | 0 | 2 | available | available | 2021-07-21T12:20:01.406 | 2021-09-22T16:39:15.401639 | 2 | Group Stage | Bakı Olimpiya Stadionu | Artur Manuel Ribeiro Soares Dias | 1.1.0 | 2 | 2 |
30 | 3788773 | 2021-06-23 | 21:00:00.000 | Europe - UEFA Euro | 2020 | Portugal | France | 2 | 2 | available | available | 2021-06-26T12:36:01.696 | 2021-09-22T16:40:30.061731 | 3 | Group Stage | Puskás Aréna | Antonio Miguel Mateu Lahoz | 1.1.0 | 2 | 2 |
31 | 3788762 | 2021-06-19 | 21:00:00.000 | Europe - UEFA Euro | 2020 | Spain | Poland | 1 | 1 | available | available | 2021-09-06T18:23:20.676161 | 2021-09-22T16:39:57.984744 | 2 | Group Stage | Estadio Olímpico de Sevilla (Sevilla) | Daniele Orsato | 1.1.0 | 2 | 2 |
32 | 3788760 | 2021-06-18 | 18:00:00.000 | Europe - UEFA Euro | 2020 | Croatia | Czech Republic | 1 | 1 | available | available | 2021-06-20T13:06:34.043 | 2021-09-22T16:39:41.325366 | 2 | Group Stage | Hampden Park | Carlos del Cerro Grande | 1.1.0 | 2 | 2 |
33 | 3788747 | 2021-06-13 | 18:00:00.000 | Europe - UEFA Euro | 2020 | Austria | North Macedonia | 3 | 1 | available | available | 2021-07-07T13:09:42.891 | 2021-09-22T16:38:29.289107 | 1 | Group Stage | Arena Naţională (Bucureşti) | Lars Christian Andreas Ekberg | 1.1.0 | 2 | 2 |
34 | 3788741 | 2021-06-11 | 21:00:00.000 | Europe - UEFA Euro | 2020 | Turkey | Italy | 0 | 3 | available | available | 2021-06-12T12:49:02.070 | 2021-09-22T16:38:05.059090 | 1 | Group Stage | Stadio Olimpico (Roma) | Danny Desmond Makkelie | 1.1.0 | 2 | 2 |
35 | 3795220 | 2021-07-06 | 21:00:00.000 | Europe - UEFA Euro | 2020 | Italy | Spain | 1 | 1 | available | available | 2021-08-09T20:41:31.241 | 2021-09-22T22:25:01.866198 | 6 | Semi-finals | Wembley Stadium (London) | Felix Brych | 1.1.0 | 2 | 2 |
36 | 3788770 | 2021-06-21 | 18:00:00.000 | Europe - UEFA Euro | 2020 | North Macedonia | Netherlands | 0 | 3 | available | available | 2021-09-26T22:04:17.453438 | 2021-09-22T16:40:19.277847 | 3 | Group Stage | Johan Cruijff Arena (Amsterdam) | Istvan Kovacs | 1.1.0 | 2 | 2 |
37 | 3795108 | 2021-07-02 | 18:00:00.000 | Europe - UEFA Euro | 2020 | Switzerland | Spain | 1 | 1 | available | available | 2021-07-03T12:52:01.320 | 2021-09-22T23:54:54.823237 | 5 | Quarter-finals | Saint-Petersburg Stadium | Michael Oliver | 1.1.0 | 2 | 2 |
38 | 3795187 | 2021-07-03 | 21:00:00.000 | Europe - UEFA Euro | 2020 | Ukraine | England | 0 | 4 | available | available | 2021-07-04T16:39:20.746 | 2021-09-22T22:09:58.374195 | 5 | Quarter-finals | Stadio Olimpico (Roma) | Felix Brych | 1.1.0 | 2 | 2 |
39 | 3795109 | 2021-07-03 | 18:00:00.000 | Europe - UEFA Euro | 2020 | Czech Republic | Denmark | 1 | 2 | available | available | 2021-07-04T13:05:32.832 | 2021-09-22T22:16:30.439245 | 5 | Quarter-finals | Bakı Olimpiya Stadionu | Björn Kuipers | 1.1.0 | 2 | 2 |
40 | 3788756 | 2021-06-17 | 21:00:00.000 | Europe - UEFA Euro | 2020 | Netherlands | Austria | 2 | 0 | available | available | 2021-06-19T12:26:56.636 | 2021-09-22T16:39:30.498704 | 2 | Group Stage | Johan Cruijff Arena (Amsterdam) | Orel Grinfeeld | 1.1.0 | 2 | 2 |
41 | 3788749 | 2021-06-14 | 18:00:00.000 | Europe - UEFA Euro | 2020 | Poland | Slovakia | 1 | 2 | available | available | 2021-06-15T13:11:56.412 | 2021-09-22T16:38:40.632586 | 1 | Group Stage | Saint-Petersburg Stadium | Ovidiu Alin Hațegan | 1.1.0 | 2 | 2 |
42 | 3788750 | 2021-06-14 | 21:00:00.000 | Europe - UEFA Euro | 2020 | Spain | Sweden | 0 | 0 | available | available | 2021-06-16T12:30:09.207 | 2021-09-22T16:38:45.960182 | 1 | Group Stage | Estadio Olímpico de Sevilla (Sevilla) | Slavko Vinčić | 1.1.0 | 2 | 2 |
43 | 3788748 | 2021-06-14 | 15:00:00.000 | Europe - UEFA Euro | 2020 | Scotland | Czech Republic | 0 | 2 | available | available | 2021-08-08T19:08:28.233 | 2021-09-22T16:38:50.097013 | 1 | Group Stage | Hampden Park | Daniel Siebert | 1.1.0 | 2 | 2 |
44 | 3788751 | 2021-06-15 | 21:00:00.000 | Europe - UEFA Euro | 2020 | France | Germany | 1 | 0 | available | available | 2021-08-27T17:33:01.458 | 2021-09-22T16:38:55.619552 | 1 | Group Stage | Allianz Arena (München) | Carlos del Cerro Grande | 1.1.0 | 2 | 2 |
45 | 3788752 | 2021-06-15 | 18:00:00.000 | Europe - UEFA Euro | 2020 | Hungary | Portugal | 0 | 3 | available | available | 2021-06-17T16:25:36.822 | 2021-09-22T16:39:00.060517 | 1 | Group Stage | Puskás Aréna | Cüneyt Çakιr | 1.1.0 | 2 | 2 |
46 | 3788742 | 2021-06-12 | 18:00:00.000 | Europe - UEFA Euro | 2020 | Denmark | Finland | 0 | 1 | available | available | 2021-06-14T12:52:32.995 | 2021-09-22T16:38:10.544627 | 1 | Group Stage | Nya Parken | Anthony Taylor | 1.1.0 | 2 | 2 |
47 | 3788775 | 2021-06-23 | 18:00:00.000 | Europe - UEFA Euro | 2020 | Slovakia | Spain | 0 | 5 | available | available | 2021-06-24T03:38:10.494 | 2021-09-22T16:40:35.297256 | 3 | Group Stage | Estadio Olímpico de Sevilla (Sevilla) | Björn Kuipers | 1.1.0 | 2 | 2 |
48 | 3788776 | 2021-06-23 | 18:00:00.000 | Europe - UEFA Euro | 2020 | Sweden | Poland | 3 | 2 | available | available | 2021-06-24T15:06:44.531 | 2021-09-22T16:40:38.194520 | 3 | Group Stage | Saint-Petersburg Stadium | Michael Oliver | 1.1.0 | 2 | 2 |
49 | 3788743 | 2021-06-12 | 21:00:00.000 | Europe - UEFA Euro | 2020 | Belgium | Russia | 3 | 0 | available | available | 2021-06-13T13:10:11.602 | 2021-09-22T16:38:15.368959 | 1 | Group Stage | Saint-Petersburg Stadium | Antonio Miguel Mateu Lahoz | 1.1.0 | 2 | 2 |
50 | 3788744 | 2021-06-12 | 15:00:00.000 | Europe - UEFA Euro | 2020 | Wales | Switzerland | 1 | 1 | available | available | 2021-06-20T12:57:59.258 | 2021-09-22T16:38:18.433799 | 1 | Group Stage | Bakı Olimpiya Stadionu | Clément Turpin | 1.1.0 | 2 | 2 |
match_id = 3788764
lineups = sb.lineups(match_id=match_id)
events = sb.events(match_id=match_id)
match_frames = sb.frames(match_id=match_id, fmt='dataframe')
match_frames[['x','y']] = pd.DataFrame(match_frames.location.tolist(), index= match_frames.index)
credentials were not supplied. open data access only credentials were not supplied. open data access only credentials were not supplied. open data access only
lineups['Germany']
player_id | player_name | player_nickname | jersey_number | country | cards | positions | |
---|---|---|---|---|---|---|---|
0 | 3053 | Leroy Sané | None | 19 | Germany | [] | [{'position_id': 23, 'position': 'Center Forwa... |
1 | 3167 | Antonio Rüdiger | None | 2 | Germany | [] | [{'position_id': 5, 'position': 'Left Center B... |
2 | 3493 | Emre Can | None | 23 | Germany | [] | [{'position_id': 4, 'position': 'Center Back',... |
3 | 4440 | Kevin Trapp | None | 22 | Germany | [] | [] |
4 | 5557 | Timo Werner | None | 11 | Germany | [] | [] |
5 | 5562 | Thomas Müller | None | 25 | Germany | [] | [{'position_id': 18, 'position': 'Right Attack... |
6 | 5570 | Manuel Neuer | None | 1 | Germany | [] | [{'position_id': 1, 'position': 'Goalkeeper', ... |
7 | 5572 | Mats Hummels | None | 5 | Germany | [] | [{'position_id': 4, 'position': 'Center Back',... |
8 | 5574 | Toni Kroos | None | 8 | Germany | [] | [{'position_id': 11, 'position': 'Left Defensi... |
9 | 5579 | Joshua Kimmich | None | 6 | Germany | [] | [{'position_id': 7, 'position': 'Right Wing Ba... |
10 | 6322 | Niklas Süle | None | 15 | Germany | [] | [{'position_id': 9, 'position': 'Right Defensi... |
11 | 6324 | Leon Goretzka | None | 18 | Germany | [] | [{'position_id': 20, 'position': 'Left Attacki... |
12 | 6985 | Robin Gosens | None | 20 | Germany | [] | [{'position_id': 8, 'position': 'Left Wing Bac... |
13 | 8215 | Kevin Volland | None | 9 | Germany | [] | [] |
14 | 8400 | Serge Gnabry | None | 10 | Germany | [] | [{'position_id': 23, 'position': 'Center Forwa... |
15 | 8525 | Marcel Halstenberg | None | 3 | Germany | [] | [{'position_id': 8, 'position': 'Left Wing Bac... |
16 | 8808 | Matthias Ginter | None | 4 | Germany | [{'time': '76:38', 'card_type': 'Yellow Card',... | [{'position_id': 3, 'position': 'Right Center ... |
17 | 8945 | Christian Günter | None | 26 | Germany | [] | [] |
18 | 8966 | Kai Havertz | None | 7 | Germany | [{'time': '65:25', 'card_type': 'Yellow Card',... | [{'position_id': 20, 'position': 'Left Attacki... |
19 | 10287 | İlkay Gündoğan | None | 21 | Germany | [] | [{'position_id': 9, 'position': 'Right Defensi... |
20 | 12323 | Florian Neuhaus | None | 17 | Germany | [] | [] |
21 | 13294 | Robin Koch | None | 24 | Germany | [] | [] |
22 | 15581 | Bernd Leno | None | 12 | Germany | [] | [] |
pid, name = 6985,'Robin Gosens'
with pd.option_context('display.max_rows', None, 'display.max_columns', None): # more options can be specified also
display(events[events.player_id==pid].iloc[0].T)
ball_receipt_outcome NaN ball_recovery_recovery_failure NaN block_deflection NaN block_offensive NaN carry_end_location NaN clearance_aerial_won NaN clearance_body_part NaN clearance_head NaN clearance_left_foot NaN clearance_right_foot NaN counterpress NaN dribble_outcome NaN dribble_overrun NaN duel_outcome NaN duel_type NaN duration 0.767229 foul_committed_advantage NaN foul_committed_card NaN foul_committed_type NaN foul_won_advantage NaN foul_won_defensive NaN goalkeeper_body_part NaN goalkeeper_end_location NaN goalkeeper_outcome NaN goalkeeper_position NaN goalkeeper_technique NaN goalkeeper_type NaN id 2b893a26-046a-43a9-927d-d45598595a81 index 42 injury_stoppage_in_chain NaN interception_outcome NaN location [102.5, 3.0] match_id 3788764 minute 0 off_camera NaN out NaN pass_aerial_won NaN pass_angle 1.374596 pass_assisted_shot_id NaN pass_body_part Left Foot pass_cross NaN pass_cut_back NaN pass_deflected NaN pass_end_location [105.7, 19.1] pass_goal_assist NaN pass_height Ground Pass pass_inswinging NaN pass_length 16.414932 pass_no_touch NaN pass_outcome NaN pass_outswinging NaN pass_recipient Kai Havertz pass_shot_assist NaN pass_switch NaN pass_technique NaN pass_through_ball NaN pass_type NaN period 1 play_pattern From Kick Off player Robin Gosens player_id 6985.0 position Left Wing Back possession 2 possession_team Germany possession_team_id 770 related_events [f3e38744-b67b-4d50-b251-680a1a2d2123] second 30 shot_body_part NaN shot_end_location NaN shot_first_time NaN shot_freeze_frame NaN shot_key_pass_id NaN shot_open_goal NaN shot_outcome NaN shot_statsbomb_xg NaN shot_technique NaN shot_type NaN substitution_outcome NaN substitution_replacement NaN tactics NaN team Germany timestamp 00:00:30.866 type Pass under_pressure NaN Name: 18, dtype: object
match_frames[match_frames.id=='2b893a26-046a-43a9-927d-d45598595a81']
teammate | actor | keeper | location | id | visible_area | match_id | x | y | |
---|---|---|---|---|---|---|---|---|---|
529 | False | False | False | [90.27666, 37.98272] | 2b893a26-046a-43a9-927d-d45598595a81 | [120.0, 0.0, 120.0, 19.3244033355597, 92.86066... | 3788764 | 90.276660 | 37.982720 |
530 | False | False | False | [95.283005, 16.7601] | 2b893a26-046a-43a9-927d-d45598595a81 | [120.0, 0.0, 120.0, 19.3244033355597, 92.86066... | 3788764 | 95.283005 | 16.760100 |
531 | True | False | False | [96.5817, 43.41135] | 2b893a26-046a-43a9-927d-d45598595a81 | [120.0, 0.0, 120.0, 19.3244033355597, 92.86066... | 3788764 | 96.581700 | 43.411350 |
532 | False | False | False | [98.46088, 52.73351] | 2b893a26-046a-43a9-927d-d45598595a81 | [120.0, 0.0, 120.0, 19.3244033355597, 92.86066... | 3788764 | 98.460880 | 52.733510 |
533 | False | False | False | [100.49047, 21.92496] | 2b893a26-046a-43a9-927d-d45598595a81 | [120.0, 0.0, 120.0, 19.3244033355597, 92.86066... | 3788764 | 100.490470 | 21.924960 |
534 | True | False | False | [101.17361, 17.428257] | 2b893a26-046a-43a9-927d-d45598595a81 | [120.0, 0.0, 120.0, 19.3244033355597, 92.86066... | 3788764 | 101.173610 | 17.428257 |
535 | True | True | False | [102.38295, 1.5539799] | 2b893a26-046a-43a9-927d-d45598595a81 | [120.0, 0.0, 120.0, 19.3244033355597, 92.86066... | 3788764 | 102.382950 | 1.553980 |
536 | False | False | False | [103.71181, 7.565845] | 2b893a26-046a-43a9-927d-d45598595a81 | [120.0, 0.0, 120.0, 19.3244033355597, 92.86066... | 3788764 | 103.711810 | 7.565845 |
537 | True | False | False | [106.549484, 33.877693] | 2b893a26-046a-43a9-927d-d45598595a81 | [120.0, 0.0, 120.0, 19.3244033355597, 92.86066... | 3788764 | 106.549484 | 33.877693 |
538 | False | False | False | [107.0708, 29.898258] | 2b893a26-046a-43a9-927d-d45598595a81 | [120.0, 0.0, 120.0, 19.3244033355597, 92.86066... | 3788764 | 107.070800 | 29.898258 |
539 | False | False | False | [107.13862, 36.549755] | 2b893a26-046a-43a9-927d-d45598595a81 | [120.0, 0.0, 120.0, 19.3244033355597, 92.86066... | 3788764 | 107.138620 | 36.549755 |
def plot_event(event, match_frames, lineups):
if len(match_frames[match_frames.id==event.id])>0:
fig, ax, pitch = plot_frame(event, match_frames[match_frames.id==event.id], lineups)
else:
fig, ax, pitch = None, None, None
return fig, ax, pitch
def plot_frame(df_event, df_freeze_frame, df_lineups, plot_event=True, show_logo=False):
# strings for team names
team1 = df_event.possession_team
try:
team2 = (set(lineups.keys()) - set([team1])).pop()
except KeyError:
team2 = '?'
# subset the team shooting, and the opposition (goalkeeper/ other)
df_team1 = df_freeze_frame[df_freeze_frame.teammate]
df_team2_goal = df_freeze_frame[df_freeze_frame.keeper]
df_team2_other = df_freeze_frame[(~df_freeze_frame.teammate) &
(~df_freeze_frame.keeper)]
# Setup the pitch
fig, ax = plt.subplots(figsize = (4*3, 3*3))
pitch = mpls.pitch.VerticalPitch(half=True, tight_layout=False, goal_type='box', pitch_color='#c2d59d', line_color='white')
# pitch = mpls.pitch.Pitch(half=False, tight_layout=False, goal_type='box', pitch_color='#c2d59d', line_color='white')
pitch.draw(ax=ax)
x,y = df_freeze_frame[df_freeze_frame.actor][['x','y']].values[0]
# plot the shot
if plot_event:
pitch.lines(x,y, df_event.pass_end_location[0], df_event.pass_end_location[1],
comet=True, label='shot', color='darkblue', ax=ax)
# plot the jersey number
df_lineup_possession = df_lineups[df_event.possession_team]
pitch.annotate(df_lineup_possession[df_lineup_possession.player_id==df_event['player_id']].jersey_number.values[0],
(x,y), va='center', ha='center', color='black', fontsize=10, ax=ax)
# plot the players
sc1 = pitch.scatter(df_team1.x, df_team1.y, s=300, c='white', edgecolors='black', label='Germany', ax=ax)
sc2 = pitch.scatter(df_team2_other.x, df_team2_other.y, s=300,
c='red', edgecolors='green', label='Portugal', ax=ax)
sc3 = pitch.scatter(df_team2_goal.x, df_team2_goal.y, s=300,
c='purple', label='Goalkeeper', ax=ax)
# add a legend and title
legend = ax.legend(loc='lower right', labelspacing=1, fontsize=15)
title = ax.set_title(f'{df_event.player}\n{team1} vs. {team2}', fontsize=20)
visible_area = np.array(df_freeze_frame.visible_area.values[0])
pitch.polygon([visible_area.reshape(int(len(visible_area)/2),2)], ax=ax, facecolors='gray', alpha=0.3)
return fig, ax, pitch
plot_event(events[events.player_id==pid].iloc[0], match_frames, lineups)
(<Figure size 864x648 with 1 Axes>, <AxesSubplot:title={'center':'Robin Gosens\nGermany vs. Portugal'}>, VerticalPitch(pitch_type='statsbomb', half=True, pitch_color='#c2d59d', line_color='white', linewidth=2, line_zorder=0.9, stripe=False, stripe_color='#c2d59d', stripe_zorder=0.6, pad_left=4, pad_right=4, pad_bottom=4, pad_top=4, positional=False, positional_zorder=0.8, positional_linewidth=2, positional_linestyle=None, positional_color='#eadddd', shade_middle=False, shade_color='#f2f2f2', shade_zorder=0.7, pitch_length=None, pitch_width=None, goal_type='box', goal_alpha=1, line_alpha=1, label=False, tick=False, axis=False, spot_scale=0.002))
filename = 'output\Gosens_vs_Portugal.mp4'
anim = animation(filename, fps=1)
for i, event in events[(events.pass_recipient=='Robin Gosens')].iterrows():
if event.pass_end_location[0] > 80:
fig, ax, pitch = plot_event(event, match_frames, lineups)
if fig:
anim.add_frame(fig)
anim.add_frame(fig)
plt.close(fig)
anim.close()