sportowe_wizualizacja/11tegen11gif.ipynb

1135 lines
86 KiB
Plaintext
Raw Normal View History

{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "11tegen11gif.ipynb",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "code",
"metadata": {
"id": "9PUEaHPDlLi5",
"colab_type": "code",
"outputId": "10d7d0a5-2b22-4100-90bf-fbb43744fb85",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 153
}
},
"source": [
"!git clone https://github.com/statsbomb/open-data.git"
],
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"text": [
"Cloning into 'open-data'...\n",
"remote: Enumerating objects: 600, done.\u001b[K\n",
"remote: Counting objects: 100% (600/600), done.\u001b[K\n",
"remote: Compressing objects: 100% (271/271), done.\u001b[K\n",
"remote: Total 6950 (delta 519), reused 407 (delta 326), pack-reused 6350\u001b[K\n",
"Receiving objects: 100% (6950/6950), 729.86 MiB | 24.95 MiB/s, done.\n",
"Resolving deltas: 100% (6161/6161), done.\n",
"Checking out files: 100% (1273/1273), done.\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "p_6BurGVpHeE",
"colab_type": "code",
"colab": {}
},
"source": [
"#edit only this tab\n",
"#give the folder path of the match\n",
"path = \"/content/open-data/data/events/\"\n",
"home_team = 'Espanyol'\n",
"away_team = 'Barcelona'"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "HaXB1D8ipuyY",
"colab_type": "code",
"outputId": "6bc862c3-96e4-4650-a1f3-544cd0916661",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
}
},
"source": [
"import PIL\n",
"import imageio\n",
"from IPython import display\n",
"import json\n",
"import os\n",
"import codecs\n",
"from pandas.io.json import json_normalize\n",
"import numpy as np\n",
"#import seaborn as sns\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"from matplotlib.patches import Arc, Rectangle, ConnectionPatch\n",
"from matplotlib.offsetbox import OffsetImage\n",
"#import squarify\n",
"from functools import reduce\n",
"\n",
"Xg_req = pd.DataFrame(data=None)\n",
"for filename in (os.listdir(path)):\n",
" #print(filename)\n",
" filename = '69275.json' # remove the comment line to work for this match\n",
"with codecs.open(\"%s\" % path + filename,encoding='utf-8') as data_file: \n",
" data = json.load(data_file)\n",
" df = pd.DataFrame(data=None)\n",
" \n",
" df = json_normalize(data, sep = \"_\")\n",
" \n",
" #df = df[(df['type_name'] == \"Shot\")]\n",
" #df = df.loc[:,['location','shot_body_part_id','shot_end_location','shot_one_on_one','shot_technique_id','shot_type_id','under_pressure','shot_outcome_id']]\n",
" #print(df.shape)\n",
"Xg_req = Xg_req.append(df,ignore_index=True,sort=False)\n",
" #df.drop(df.index, inplace=True)\n",
" \n",
"print(\"done\")\n",
"df = Xg_req"
],
"execution_count": 85,
"outputs": [
{
"output_type": "stream",
"text": [
"done\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "Hs2plpAcqXNm",
"colab_type": "code",
"colab": {}
},
"source": [
"#type_id=30 is pass event AND type_id=19 is substitution event\n",
"\n",
"pass_m = df.query('type_id == 30')\n",
"substitution = df.query('type_id == 19')\n",
"#pass_m = df.query('type_name == pass')\n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "lJEuZAIfqcbR",
"colab_type": "code",
"outputId": "826f8fd3-1399-4f2f-bcda-0e9bd77f85ee",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 51
}
},
"source": [
"#this cell is WIP\n",
"substitution_home = set()\n",
"substitution_home = substitution[substitution.team_name == home_team]\n",
"substitution_home = substitution_home['substitution_replacement_name'].unique()\n",
"substitution_away = set()\n",
"substitution_away = substitution[substitution.team_name == away_team]\n",
"substitution_away = substitution_away['substitution_replacement_name'].unique()\n",
"print(substitution_away)\n",
"print(substitution_home)"
],
"execution_count": 87,
"outputs": [
{
"output_type": "stream",
"text": [
"['Javier Alejandro Mascherano' 'Seydou Kéita' 'Bojan Krkíc Pérez']\n",
"['Jesús Alberto Dátolo' 'Jordi Amat Maas' 'David García De La Cruz']\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "EcI20iZJqd67",
"colab_type": "code",
"colab": {}
},
"source": [
"# to get \n",
"\n",
"home_player = pass_m[(pass_m.team_name == home_team)] \n",
"home_team_list = set()\n",
"home_team_list = home_player['player_name'].unique()\n",
"#print(substitution_belgium)\n",
"#belgium_list = [player for player in belgium_list if player not in substitution_belgium]\n",
"#belgium_list.remove([x for x in substitution_belgium])#belgium_list - substitution_belgium\n",
"home_player =pass_m['player_name'].isin(home_team_list)\n",
"pass_home = pass_m[home_player] #contains 11 players of home team\n",
"\n",
"away_player = pass_m[(pass_m.team_name == away_team)] \n",
"away_list = away_player['player_name'].unique()\n",
"#away_list = away_list - substitution_brazil\n",
"away_player = pass_m['player_name'].isin(away_list)\n",
"pass_away = pass_m[away_player]"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "lzKdQhmSqfnn",
"colab_type": "code",
"outputId": "e1700207-3fd6-4234-e6ec-2c4f4d6efcb0",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 457
}
},
"source": [
"pass_home.head()"
],
"execution_count": 89,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>50_50_outcome_id</th>\n",
" <th>50_50_outcome_name</th>\n",
" <th>bad_behaviour_card_id</th>\n",
" <th>bad_behaviour_card_name</th>\n",
" <th>ball_receipt_outcome_id</th>\n",
" <th>ball_receipt_outcome_name</th>\n",
" <th>ball_recovery_recovery_failure</th>\n",
" <th>block_deflection</th>\n",
" <th>block_offensive</th>\n",
" <th>carry_end_location</th>\n",
" <th>clearance_aerial_won</th>\n",
" <th>clearance_body_part_id</th>\n",
" <th>clearance_body_part_name</th>\n",
" <th>clearance_head</th>\n",
" <th>clearance_left_foot</th>\n",
" <th>clearance_right_foot</th>\n",
" <th>counterpress</th>\n",
" <th>dribble_nutmeg</th>\n",
" <th>dribble_outcome_id</th>\n",
" <th>dribble_outcome_name</th>\n",
" <th>dribble_overrun</th>\n",
" <th>duel_outcome_id</th>\n",
" <th>duel_outcome_name</th>\n",
" <th>duel_type_id</th>\n",
" <th>duel_type_name</th>\n",
" <th>duration</th>\n",
" <th>foul_committed_advantage</th>\n",
" <th>foul_committed_card_id</th>\n",
" <th>foul_committed_card_name</th>\n",
" <th>foul_committed_offensive</th>\n",
" <th>foul_committed_type_id</th>\n",
" <th>foul_committed_type_name</th>\n",
" <th>foul_won_advantage</th>\n",
" <th>foul_won_defensive</th>\n",
" <th>goalkeeper_body_part_id</th>\n",
" <th>goalkeeper_body_part_name</th>\n",
" <th>goalkeeper_end_location</th>\n",
" <th>goalkeeper_outcome_id</th>\n",
" <th>goalkeeper_outcome_name</th>\n",
" <th>goalkeeper_position_id</th>\n",
" <th>...</th>\n",
" <th>period</th>\n",
" <th>play_pattern_id</th>\n",
" <th>play_pattern_name</th>\n",
" <th>player_id</th>\n",
" <th>player_name</th>\n",
" <th>position_id</th>\n",
" <th>position_name</th>\n",
" <th>possession</th>\n",
" <th>possession_team_id</th>\n",
" <th>possession_team_name</th>\n",
" <th>related_events</th>\n",
" <th>second</th>\n",
" <th>shot_aerial_won</th>\n",
" <th>shot_body_part_id</th>\n",
" <th>shot_body_part_name</th>\n",
" <th>shot_end_location</th>\n",
" <th>shot_first_time</th>\n",
" <th>shot_freeze_frame</th>\n",
" <th>shot_key_pass_id</th>\n",
" <th>shot_one_on_one</th>\n",
" <th>shot_outcome_id</th>\n",
" <th>shot_outcome_name</th>\n",
" <th>shot_redirect</th>\n",
" <th>shot_statsbomb_xg</th>\n",
" <th>shot_technique_id</th>\n",
" <th>shot_technique_name</th>\n",
" <th>shot_type_id</th>\n",
" <th>shot_type_name</th>\n",
" <th>substitution_outcome_id</th>\n",
" <th>substitution_outcome_name</th>\n",
" <th>substitution_replacement_id</th>\n",
" <th>substitution_replacement_name</th>\n",
" <th>tactics_formation</th>\n",
" <th>tactics_lineup</th>\n",
" <th>team_id</th>\n",
" <th>team_name</th>\n",
" <th>timestamp</th>\n",
" <th>type_id</th>\n",
" <th>type_name</th>\n",
" <th>under_pressure</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>0.606100</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>...</td>\n",
" <td>1</td>\n",
" <td>9</td>\n",
" <td>From Kick Off</td>\n",
" <td>26609.0</td>\n",
" <td>Pablo Daniel Osvaldo</td>\n",
" <td>23.0</td>\n",
" <td>Center Forward</td>\n",
" <td>2</td>\n",
" <td>214</td>\n",
" <td>Espanyol</td>\n",
" <td>[ca57ebcb-f65d-4d0c-b54d-c2ea0ccb8553]</td>\n",
" <td>0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>214</td>\n",
" <td>Espanyol</td>\n",
" <td>00:00:00.738</td>\n",
" <td>30</td>\n",
" <td>Pass</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>1.776163</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>...</td>\n",
" <td>1</td>\n",
" <td>9</td>\n",
" <td>From Kick Off</td>\n",
" <td>26211.0</td>\n",
" <td>Joan Verdú Fernández</td>\n",
" <td>21.0</td>\n",
" <td>Left Wing</td>\n",
" <td>2</td>\n",
" <td>214</td>\n",
" <td>Espanyol</td>\n",
" <td>[cb6b2c06-a935-4588-b7cb-e1e952c9ddbe]</td>\n",
" <td>2</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>214</td>\n",
" <td>Espanyol</td>\n",
" <td>00:00:02.511</td>\n",
" <td>30</td>\n",
" <td>Pass</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>1.242900</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>...</td>\n",
" <td>1</td>\n",
" <td>9</td>\n",
" <td>From Kick Off</td>\n",
" <td>7029.0</td>\n",
" <td>José María Callejón Bueno</td>\n",
" <td>17.0</td>\n",
" <td>Right Wing</td>\n",
" <td>2</td>\n",
" <td>214</td>\n",
" <td>Espanyol</td>\n",
" <td>[34e65d1a-4eca-4b55-8340-d125a8a32808, a6aedc7...</td>\n",
" <td>9</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>214</td>\n",
" <td>Espanyol</td>\n",
" <td>00:00:09.581</td>\n",
" <td>30</td>\n",
" <td>Pass</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>1.298500</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>...</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>From Throw In</td>\n",
" <td>6886.0</td>\n",
" <td>Dídac Vilá Rosselló</td>\n",
" <td>6.0</td>\n",
" <td>Left Back</td>\n",
" <td>3</td>\n",
" <td>214</td>\n",
" <td>Espanyol</td>\n",
" <td>[98eb8c82-78c5-4c62-8c1b-02f5194eec55]</td>\n",
" <td>18</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>214</td>\n",
" <td>Espanyol</td>\n",
" <td>00:00:18.784</td>\n",
" <td>30</td>\n",
" <td>Pass</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>0.950262</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>...</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>From Throw In</td>\n",
" <td>24783.0</td>\n",
" <td>Javier Márquez Moreno</td>\n",
" <td>13.0</td>\n",
" <td>Right Center Midfield</td>\n",
" <td>3</td>\n",
" <td>214</td>\n",
" <td>Espanyol</td>\n",
" <td>[1323492f-0fdc-4df7-bfd2-1a3f8c7b63e5, e27e148...</td>\n",
" <td>20</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>214</td>\n",
" <td>Espanyol</td>\n",
" <td>00:00:20.122</td>\n",
" <td>30</td>\n",
" <td>Pass</td>\n",
" <td>True</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 122 columns</p>\n",
"</div>"
],
"text/plain": [
" 50_50_outcome_id 50_50_outcome_name ... type_name under_pressure\n",
"4 NaN NaN ... Pass NaN\n",
"8 NaN NaN ... Pass NaN\n",
"16 NaN NaN ... Pass True\n",
"20 NaN NaN ... Pass NaN\n",
"24 NaN NaN ... Pass True\n",
"\n",
"[5 rows x 122 columns]"
]
},
"metadata": {
"tags": []
},
"execution_count": 89
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "b81BeCpOqhel",
"colab_type": "code",
"colab": {}
},
"source": [
"def draw_pitch(ax):\n",
" # focus on only half of the pitch\n",
" #Pitch Outline & Centre Line\n",
" Pitch = Rectangle([0,0], width = 120, height = 80, fill = False)\n",
" #Left, Right Penalty Area and midline\n",
" LeftPenalty = Rectangle([0,22.3], width = 14.6, height = 35.3, fill = False)\n",
" RightPenalty = Rectangle([105.4,22.3], width = 14.6, height = 35.3, fill = False)\n",
" midline = ConnectionPatch([60,0], [60,80], \"data\", \"data\")\n",
"\n",
" #Left, Right 6-yard Box\n",
" LeftSixYard = Rectangle([0,32], width = 4.9, height = 16, fill = False)\n",
" RightSixYard = Rectangle([115.1,32], width = 4.9, height = 16, fill = False)\n",
"\n",
"\n",
" #Prepare Circles\n",
" centreCircle = plt.Circle((60,40),8.1,color=\"white\", fill = False)\n",
" centreSpot = plt.Circle((60,40),0.71,color=\"white\")\n",
" #Penalty spots and Arcs around penalty boxes\n",
" leftPenSpot = plt.Circle((9.7,40),0.71,color=\"white\")\n",
" rightPenSpot = plt.Circle((110.3,40),0.71,color=\"white\")\n",
" leftArc = Arc((9.7,40),height=16.2,width=16.2,angle=0,theta1=310,theta2=50,color=\"white\")\n",
" rightArc = Arc((110.3,40),height=16.2,width=16.2,angle=0,theta1=130,theta2=230,color=\"white\")\n",
" \n",
" element = [Pitch, LeftPenalty, RightPenalty, midline, LeftSixYard, RightSixYard, centreCircle, \n",
" centreSpot, rightPenSpot, leftPenSpot, leftArc, rightArc]\n",
" for i in element:\n",
" ax.add_patch(i)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "dlpn4HOe6UUg",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
},
"outputId": "487a0839-e0f5-4266-aeae-845b55eddf72"
},
"source": [
"filenames_home = []\n",
"players = home_team_list #['Alisson Ramsés Becker','Fágner Conserva Lemos','Fernando Luiz Rosa','Gabriel Fernando de Jesus','João Miranda de Souza Filho','José Paulo Bezzera Maciel Júnior','Marcelo Vieira da Silva Júnior','Neymar da Silva Santos Junior','Philippe Coutinho Correia','Thiago Emiliano da Silva','Willian Borges da Silva']\n",
"fig=plt.figure() #set up the figures\n",
"from matplotlib import rcParams\n",
"plt.style.use('dark_background')\n",
"fig.set_size_inches(16,9)\n",
"ax=fig.add_subplot(1,1,1)\n",
"draw_pitch(ax) #overlay our different objects on the pitch\n",
"plt.ylim(-2, 82)\n",
"plt.xlim(-2, 122)\n",
"plt.axis('off')\n",
"y_loc =0\n",
"timestamp = ['00:10:00:000','00:15:00:000','00:20:00:000','00:25:00:000','00:30:00:000','00:35:00:000','00:40:00:000','00:45:00:000','00:50:00:000']\n",
"time = 0\n",
"half =1\n",
"while (time < len(timestamp) ):\n",
" for player in players:\n",
" x_avg = 0\n",
" y_avg = 0\n",
" touches = 0\n",
" if player in players:\n",
" #print(players[player])\n",
" if time != 0:\n",
" #print('YES.',timestamp[time])\n",
" play_temp = pass_home[ (pass_home.timestamp > timestamp[time-1]) & (pass_home.timestamp <= timestamp[time])]\n",
" else:\n",
" play_temp = pass_home[(pass_home.timestamp <= timestamp[time])] \n",
" \n",
" play_temp = play_temp[(play_temp.player_name == player) & (play_temp.period == half)]\n",
" \n",
" if len(play_temp) != 0:\n",
" for i in range(len(play_temp)):\n",
" touches+=1\n",
" #https://math.stackexchange.com/questions/1013230/how-to-find-coordinates-of-reflected-point\n",
" #y_loc = (play_temp.iloc[i]['location'][1] + 40 ) %80\n",
" y_loc = -2*(play_temp.iloc[i]['location'][1] - 40) + play_temp.iloc[i]['location'][1] \n",
" x_avg = x_avg + play_temp.iloc[i]['location'][0]\n",
" y_avg = y_avg + y_loc\n",
" if len(play_temp) != 0: \n",
" x_avg = x_avg/len(play_temp)\n",
" y_avg = y_avg/len(play_temp)\n",
" \n",
" ax.scatter(x_avg, y_avg, s= (5 *touches )) \n",
" ax.annotate(player, (x_avg, y_avg))\n",
" plt.text(50,-4,str(half)+' Half '+str(timestamp[time]),fontsize=20,color='#cb4154') \n",
" plt.savefig('home_image'+ str(half) + str(timestamp[time]) + str('.png'))\n",
" filenames_home.append('home_image'+ str(half) + str(timestamp[time]) + str('.png'))\n",
" plt.cla()\n",
" time +=1\n",
" if time == 8 and half ==1:\n",
" time = 0\n",
" half = 2\n",
" #fig=plt.figure()\n",
" plt.style.use('dark_background')\n",
" fig.set_size_inches(16,9)\n",
" ax=fig.add_subplot(1,1,1)\n",
" draw_pitch(ax) #overlay our different objects on the pitch\n",
" plt.ylim(-2, 82)\n",
" plt.xlim(-2, 122)\n",
" plt.axis('off')\n",
" kargs = { 'duration': 2 }\n",
"\n",
"import imageio\n",
"images = []\n",
"for filename in filenames_home:\n",
" frame = 2*(i**0.5) \n",
" images.append(imageio.imread(filename))\n",
"imageio.mimsave('home.gif', images,**kargs)\n",
"#plt.show()"
],
"execution_count": 189,
"outputs": [
{
"output_type": "stream",
"text": [
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n"
],
"name": "stderr"
},
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA54AAAIICAYAAAAGxzENAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC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fiFy0aFEsWbIkPvvss6isrIyKiopo1qxZVFZW\nRuvWrWPfffddH6l/+/PDDz+M119/PWbNmhWzZs2K119/PWbOnBmLFi3K/aEDQI2piIgi94gvUxSl\nNXHevHnRrl273DNKSlEUUVFRkXsGwL+sSZMmsffee0f37t2je/fusddee8U777yzPg7/9uebb74Z\nK1eu/Nz307t37xg6dGj07dv3C/99O+644/qY/VvcfuMb34hFixbFpEmT1p933323pj9UgCzcbtyw\nuXPnRtu2bXPPWK+mP0d1JjxL6T/OUttTClwToC7bfvvto3///nHUUUfFv/3bv8XMmTPXB9+UKVPi\n448//srvc2PDc0MqKiqiS5cu6+P3wAMPjGXLlsVjjz0W9913X0yZMiXWrVv3ld8vQClwu3HDSum6\npNjiobYA1Evbbbdd9O/fP44++uj4+te/Ho8++mhcd911MXHixFi+fHnWbUVRxPTp02P69Onxi1/8\nIiIivv71r8dhhx0WN9xwQ2yzzTZx//33x9ixY+PZZ58tuUcGAcDf86y2ANQrBx10UPzxj3+MmTNn\nxp577hkjRoyI7bbbLk444YT4j//4j+zR+XlmzpwZ11xzTey+++7RvXv3mD9/ftx8880xZ86cGDp0\naGy++ea5JwLA5xKeAJS9pk2bximnnBIzZsyIG264IR599NHYYYcd4vjjj49x48bF6tWrc0/8St56\n6624+uqrY7fddosBAwZE165dY86cOXHrrbdG586dc88DgH8gPAEoW82aNYsf//jHUV1dHQcffHCc\neeaZ0aVLl7j99tu/8ImB6pIXX3wxBg8eHJ06dYr58+fHU089FePGjYvddtst9zQAWE94AlB2GjZs\nGN///vfjzTffjN122y3222+/OOKII+Lpp5/OPS2ZBQsWxPDhw6NNmzYxbty4ePzxx+O3v/1ttGnT\nJvc0ABCeAJSXI444ImbMmBEDBw6MI444IgYOHBhvvfVW7lm1ZvXq1XHLLbdEhw4d4u23346//OUv\nMWrUqNhyyy1zTwOgHhOeAJSFbbfdNh566KG46qqr4uyzz46ePXvGiy++mHtWNsuXL4/hw4dH586d\no0mTJvHaa6/FkUcemXsWAPWU8KRGbbfddtG8efPcM4B65thjj41XXnklZsyYEbvvvnuMHz8+96SS\nsXDhwjjttNNiwIAB8dOf/jTuvffe2HrrrXPPAuqZnXfeOfcEMhOe1KhBgwbFyy+/HHvttVfuKUA9\nsO2228Yf//jHuOCCC+Lggw+OSy+9tM49Q21tee6552K33XaLd999N6ZPnx79+/fPPQmoB5o2bRq3\n3HJL/OlPf4qmTZvmnkNmRamf4n9eGbtkTqntKYXzv6/JUUcdVcyfP78YOnRo9l2O45TvOeCAA4p3\n3323uPzyy4tGjRpl3/P3p3fv3sX48eOz79jQ2XvvvYu33nqruOGGG0ry2jmOUx5nl112KWbNmlX8\n5je/KVq0aLH+f3dbesOnlK5Loi35P7C69EkoxT2lcP7+mrRu3bp46aWXijvuuMONGsdxavycccYZ\nxfz584u+fftm3/J5p5TDMyKKli1bFo888kjxzDPPFF/72tey73Ecp7zOQQcdVMyfP7848cQT/+Hv\n3Jbe8Cml65Jii
"text/plain": [
"<Figure size 1152x648 with 1 Axes>"
]
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "vi-Sar_IZ9Ri",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
},
"outputId": "0477ad03-0d55-451f-e0c9-be2098e1ad59"
},
"source": [
"filenames_away = []\n",
"players = away_list #['Alisson Ramsés Becker','Fágner Conserva Lemos','Fernando Luiz Rosa','Gabriel Fernando de Jesus','João Miranda de Souza Filho','José Paulo Bezzera Maciel Júnior','Marcelo Vieira da Silva Júnior','Neymar da Silva Santos Junior','Philippe Coutinho Correia','Thiago Emiliano da Silva','Willian Borges da Silva']\n",
"fig=plt.figure() #set up the figures\n",
"from matplotlib import rcParams\n",
"plt.style.use('dark_background')\n",
"fig.set_size_inches(16,9)\n",
"ax=fig.add_subplot(1,1,1)\n",
"draw_pitch(ax) #overlay our different objects on the pitch\n",
"plt.ylim(-2, 82)\n",
"plt.xlim(-2, 122)\n",
"plt.axis('off')\n",
"y_loc =0\n",
"timestamp = ['00:10:00:000','00:15:00:000','00:20:00:000','00:25:00:000','00:30:00:000','00:35:00:000','00:40:00:000','00:45:00:000','00:50:00:000']\n",
"time = 0\n",
"half =1\n",
"while (time < len(timestamp) ):\n",
" for player in players:\n",
" x_avg = 0\n",
" y_avg = 0\n",
" touches = 0\n",
" if player in players:\n",
" #print(players[player])\n",
" if time != 0:\n",
" #print('YES.',timestamp[time])\n",
" play_temp = pass_away[ (pass_away.timestamp > timestamp[time-1]) & (pass_away.timestamp <= timestamp[time])]\n",
" else:\n",
" play_temp = pass_away[(pass_away.timestamp <= timestamp[time])] \n",
" \n",
" play_temp = play_temp[(play_temp.player_name == player) & (play_temp.period == half)]\n",
" #print(play_temp.player_name ,play_temp.timestamp)\n",
" #print('\\n')\n",
" if len(play_temp) != 0:\n",
" for i in range(len(play_temp)):\n",
" touches+=1\n",
" #y_loc = (play_temp.iloc[i]['location'][1] + 40 ) %80\n",
" y_loc = -2*(play_temp.iloc[i]['location'][1] - 40) + play_temp.iloc[i]['location'][1] \n",
" x_avg = x_avg + play_temp.iloc[i]['location'][0]\n",
" y_avg = y_avg + y_loc\n",
" if len(play_temp) != 0: \n",
" x_avg = x_avg/len(play_temp)\n",
" y_avg = y_avg/len(play_temp)\n",
" #print(x_avg,y_avg,players[player])\n",
" ax.scatter(x_avg, y_avg, s= (5 *touches )) \n",
" ax.annotate(player, (x_avg, y_avg))\n",
" plt.text(50,-4,str(half)+' Half '+str(timestamp[time]),fontsize=20,color='#cb4154') \n",
" plt.savefig('away_image'+ str(half) + str(timestamp[time]) + str('.png'))\n",
" filenames_away.append('away_image'+ str(half) + str(timestamp[time]) + str('.png'))\n",
" plt.cla()\n",
" time +=1\n",
" if time == 8 and half ==1:\n",
" time = 0\n",
" half = 2\n",
" #fig=plt.figure()\n",
" plt.style.use('dark_background')\n",
" fig.set_size_inches(16,9)\n",
" ax=fig.add_subplot(1,1,1)\n",
" draw_pitch(ax) #overlay our different objects on the pitch\n",
" plt.ylim(-2, 82)\n",
" plt.xlim(-2, 122)\n",
" plt.axis('off')\n",
" \n",
"kargs = { 'duration': 2 }\n",
"import imageio\n",
"images = []\n",
"for filename in filenames_away:\n",
" frame = 2*(i**0.5) \n",
" images.append(imageio.imread(filename))\n",
"imageio.mimsave('away.gif', images,**kargs)"
],
"execution_count": 190,
"outputs": [
{
"output_type": "stream",
"text": [
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n",
"/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py:98: MatplotlibDeprecationWarning: \n",
"Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.\n",
" \"Adding an axes using the same arguments as a previous axes \"\n"
],
"name": "stderr"
},
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA54AAAIICAYAAAAGxzENAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3XeU1fWd//H3wCBNwUZsOICIAgmI\ncS2xQaSuxkpQDkYUNZpjiwWNsRGsIShRY0lig0RjgjW6GEGNgOiCGguCGJUyroXmCoKACHx/f+wv\nnN0EFZP5zOfOncfjnM/BE+aMr/mOmbnPuXfurYiIIgAAACCRBrkHAAAAUN6EJwAAAEkJTwAAAJIS\nngAAACQlPAEAAEhKeAIAAJCU8AQAACAp4QkAAEBSwhMAAICkhCcAAABJCU8AAACSEp4AAAAkJTwB\nAABISngCAACQlPAEAAAgKeEJAABAUsITABJo1KhRVFVV5Z4BACWhMveAjTF37txo27Zt7hkAAABl\nb968edGuXbsafZ8VEVHU6HtMoCiKqKioyD0DADZa7969Y+jQodG3b9/cUwDgK0nRXx5qCwAAQFLC\nEwAAgKSEJwAAAEkJTwAAAJISngAAACQlPAEAAEhKeAIAAJCU8AQAACAp4QkAAEBSwhMAAICkhCcA\nAABJCU8AAACSEp4AAAAkJTwBAABISngCAACQlPAEAAAgKeEJAABAUsITAACApIQnAAAASQlPAAAA\nkhKeAAAAJCU8AQAASEp4AgAAkJTwBAAAICnhCQAAQFLCEwAAgKSEJwAAAEkJTwAAAJISngAAACQl\nPAEAAEhKeAIAAJCU8AQAACAp4QkAAEBSwhMAAICkhCcAAABJCU8AAACSEp4AAAAkJTwBAABISngC\nAACQlPAEAAAgKeEJAABAUsITAACApIQnAAAASQlPAAAAkhKeAAAAJCU8AQAASEp4AgA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BSwhMAAICkhCcAAABJCU8AAACSEp4AAAAkJTwBAABISngCAACQlPAEAAAgKeEJAABA\nUsITAACApIQnAAAASQlPAAAAkhKeAAAAJFWZewAA1EUVFRWxxRZbRKtWrWLrrbeOVq1aRatWrWLz\nzTePysrK2HXXXWOnnXaKiy66KNauXRsrVqyIxYsXx+LFi2PRokWxaNGiWLx4cXz66ae5PxQASE54\nAsAXaNSoUXTq1Ck6deoUnTt3Xv/PHTp0iBUrVvyfiFy0aFEsWbIkPvvss6isrIyKiopo1qxZVFZW\nRuvWrWPfffddH6l/+/PDDz+M119/PWbNmhWzZs2K119/PWbOnBmLFi3K/aEDQI2piIgi94gvUxSl\nNXHevHnRrl273DNKSlEUUVFRkXsGwL+sSZMmsffee0f37t2je/fusddee8U777yzPg7/9uebb74Z\nK1eu/Nz307t37xg6dGj07dv3C/99O+644/qY/VvcfuMb34hFixbFpEmT1p933323pj9UgCzcbtyw\nuXPnRtu2bXPPWK+mP0d1JjxL6T/OUttTClwToC7bfvvto3///nHUUUfFv/3bv8XMmTPXB9+UKVPi\n448//srvc2PDc0MqKiqiS5cu6+P3wAMPjGXLlsVjjz0W9913X0yZMiXWrVv3ld8vQClwu3HDSum6\npNjiobYA1Evbbbdd9O/fP44++uj4+te/Ho8++mhcd911MXHixFi+fHnWbUVRxPTp02P69Onxi1/8\nIiIivv71r8dhhx0WN9xwQ2yzzTZx//33x9ixY+PZZ58tuUcGAcDf86y2ANQrBx10UPzxj3+MmTNn\nxp577hkjRoyI7bbbLk444YT4j//4j+zR+XlmzpwZ11xzTey+++7RvXv3mD9/ftx8880xZ86cGDp0\naGy++ea5JwLA5xKeAJS9pk2bximnnBIzZsyIG264IR599NHYYYcd4vjjj49x48bF6tWrc0/8St56\n6624+uqrY7fddosBAwZE165dY86cOXHrrbdG586dc88DgH8gPAEoW82aNYsf//jHUV1dHQcffHCc\neeaZ0aVLl7j99tu/8ImB6pIXX3wxBg8eHJ06dYr58+fHU089FePGjYvddtst9zQAWE94AlB2GjZs\nGN///vfjzTffjN122y3222+/OOKII+Lpp5/OPS2ZBQsWxPDhw6NNmzYxbty4ePzxx+O3v/1ttGnT\nJvc0ABCeAJSXI444ImbMmBEDBw6MI444IgYOHBhvvfVW7lm1ZvXq1XHLLbdEhw4d4u23346//OUv\nMWrUqNhyyy1zTwOgHhOeAJSFbbfdNh566KG46qqr4uyzz46ePXvGiy++mHtWNsuXL4/hw4dH586d\no0mTJvHaa6/FkUcemXsWAPWU8KRGbbfddtG8efPcM4B65thjj41XXnklZsyYEbvvvnuMHz8+96SS\nsXDhwjjttNNiwIAB8dOf/jTuvffe2HrrrXPPAuqZnXfeOfcEMhOe1KhBgwbFyy+/HHvttVfuKUA9\nsO2228Yf//jHuOCCC+Lggw+OSy+9tM49Q21tee6552K33XaLd999N6ZPnx79+/fPPQmoB5o2bRq3\n3HJL/OlPf4qmTZvmnkNmRamf4n9eGbtkTqntKYXzv6/JUUcdVcyfP78YOnRo9l2O45TvOeCAA4p3\n3323uPzyy4tGjRpl3/P3p3fv3sX48eOz79jQ2XvvvYu33nqruOGGG0ry2jmOUx5nl112KWbNmlX8\n5je/KVq0aLH+f3dbesOnlK5Loi35P7C69EkoxT2lcP7+mrRu3bp46aWXijvuuMONGsdxavycccYZ\nxfz584u+fftm3/J5p5TDMyKKli1bFo888kjxzDPPFF/72tey73Ecp7zOQQcdVMyfP7848cQT/+Hv\n3Jbe8Cml65Jii
"text/plain": [
"<Figure size 1152x648 with 1 Axes>"
]
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "cTn2YICxuUdK",
"colab_type": "code",
"colab": {}
},
"source": [
"kargs = { 'duration': 2 }\n",
"import imageio\n",
"images = []\n",
"for filename in filenames:\n",
" frame = 2*(i**0.5) \n",
" images.append(imageio.imread(filename))\n",
"imageio.mimsave('movie.gif', images,**kargs)"
],
"execution_count": 0,
"outputs": []
}
]
}