[PYTHON] Try to create a battle record table with matplotlib from the data of "Schedule-kun"

Overview

A visualization of the competition schedule and results (○, △, ●) in a tabular format is called a battle record table. I'll show you the actual graphics because it's just like this. C8A6DC2D-1EFE-4B01-8F2E-D63AE36B7596.JPG

The way this table looks is that the X-axis shows the opponents to play away and the Y-axis shows the opponents to play at home. Create such a table from the data of "Schedule-kun" using matplotlib. This is an example of how you can do this, although it is far from the standard visualization method.

Original data

Data processing

fixturetable.py


game_result = pd.read_csv("../csv/game_result_all_2020_v2.csv", encoding="utf-8")
#J1 team name list (from north) 2020 edition
team = ["Sapporo","Sendai","Kashima","Urawa","oak","FC tokyo","Kawasaki F","Yokohama FM","Yokohama FC","Shonan",
        "Shimizu","Nagoya","Gamba Osaka","C Osaka","Kobe","Hiroshima","Tosu","Oita"]
#Extract only J1 and create a new data frame
game_J1_tmp = game_result[game_result["Tournament"] == "J1"]

キャプチャ0.PNG Since it has not started yet, there is no data in "Score / Number of visitors / home_g / away_g / Results". It has nothing to do with this table, so you can ignore it.

fixturetable.py


#Create empty data frame to join
game_J1 = pd.DataFrame(index=team, columns=team)

for i, t in enumerate(team):
    # [1]Extract each opponent, section and result for each team
    team_tmp = game_J1_tmp.loc[game_J1_tmp["home"] == t, ["Away", "sec", "result"]]
    # [2]Reset the index of the acquired data
    team_tmp.reset_index(inplace=True, drop=True)
    # [3]Sec for the team of extraction conditions:Add at 99
    team_tmp.loc[17,:] = [t, 99, -1]
    # [4]Add team order data from north
    team_tmp["order"] = team_tmp["Away"].apply(lambda x: team.index(x) if x in team else -1)
    # [5]Sort from north to team
    team_tmp = team_tmp.sort_values("order")

    # [6]Expand to the row of the final data frame (team of extraction conditions).
    for x in range(len(team_tmp)):
        game_J1.iloc[i, x] = team_tmp.at[team_tmp.index[x],"sec"]

Extract each opponent, section and result for each team キャプチャ1.PNG

2 Reset the index of the acquired data キャプチャ2.PNG

3 Add the team of extraction conditions with sec: 99 キャプチャ3.PNG

4 Add team order data from north キャプチャ4.PNG

5 Sort from north to team 6 Expand to the row (team of extraction conditions) of the final data frame. キャプチャ8.PNG

This is the final form of the data. Draw this on the graph.

fixturetable.py


plt.rcParams["font.family"] = "IPAexGothic"

fig = plt.figure(figsize=(6,6),dpi=144)
ax1 = fig.add_subplot(111)

teams = np.arange(len(team)+1)
h, v = 0.5, 0.5

ax1.set_ylim(18, 0)
ax1.set_xticks(teams)
ax1.set_yticks(teams)
ax1.xaxis.tick_top()
ax1.set_xticklabels(team, rotation=90)
ax1.set_yticklabels(team)

ax1.grid(True)
ax1.tick_params(axis="both", which="both", length=0)

#Display of the event section and coloring of squares without competition
for k, t in enumerate(team):
    for i in range(18):
        if game_J1.at[game_J1.index[i], t] == 99:
            _ = patches.Rectangle(xy=(k, i), width=1.0, height=1.0, color="0.8")
            ax1.add_patch(_)
        else:
            ax1.text(k+h, i+v, game_J1.at[game_J1.index[i], t], size=12, color = "k", ha="center", va="center")

ax1.set_title("2020 Meiji Yasuda Life J1 league record table", fontsize=16)
txt = "Source: JLeague Data Site"
fig.text(.9, .1, txt, fontsize=10, horizontalalignment="right")
txt3 = str(update) + "update"
fig.text(.9, .95, txt3, fontsize=10, horizontalalignment="right")

#fig.tight_layout()
plt.savefig("../img/J1fixturetable_noemblem_2020.png ", bbox_inches="tight")

The point of creating a graph is simple

J1fixturetable_noemblem_2020.png

2019 results table

The remaining challenges

Recommended Posts

Try to create a battle record table with matplotlib from the data of "Schedule-kun"
Try to extract the features of the sensor data with CNN
Tokyo Corona: Try to make a simple prediction from open data with the exponential function curve_fit
Try to image the elevation data of the Geographical Survey Institute with Python
Create a record table from JFL match results
Create a table of contents with IPython notebook
SSH login to the target server from Windows with a click of a shortcut
Paste a link to the data point of the graph created by jupyterlab & matplotlib
I tried to create a model with the sample of Amazon SageMaker Autopilot
[Introduction to Python] How to get the index of data with a for statement
I tried to create a table only with Django
Add information to the bottom of the figure with Matplotlib
How to create a submenu with the [Blender] plugin
Try to dynamically create a Checkbutton with Python's Tkinter
Try to get the contents of Word with Golang
I want to manually create a legend with matplotlib
[Python] How to create a 2D histogram with Matplotlib
Try to create a waveform (audio spectrum) that moves according to the sound with python
Try scraping the data of COVID-19 in Tokyo with Python
A network diagram was created with the data of COVID-19.
Create a data frame from the acquired boat race text data
[Linux] Copy data from Linux to Windows with a shell script
Probably the easiest way to create a pdf with Python3
Try to extract Azure SQL Server data table with pyodbc
[Introduction to matplotlib] Read the end time from COVID-19 data ♬
Try to automate the operation of network devices with Python
The story of copying data from S3 to Google's TeamDrive
Create a correlation diagram from the conversation history of twitter
[Python] I want to make a 3D scatter plot of the epicenter with Cartopy + Matplotlib!
I made a tool to automatically generate a simple ER diagram from the CREATE TABLE statement
[Python] How to create a table from list (basic operation of table creation / change of matrix name)
How to plot the distribution of bacterial composition from Qiime2 analysis data in a box plot
Create a 2D array by adding a row to the end of an empty array with numpy
How to plot a lot of legends by changing the color of the graph continuously with matplotlib
Save the results of crawling with Scrapy to the Google Data Store
Create folders from '01' to '12' with python
[Python] Try to graph from the image of Ring Fit [OCR]
Manage the overlap when drawing scatter plots with a large amount of data (Matplotlib, Pandas, Datashader)
[Introduction to StyleGAN] I played with "The Life of a Man" ♬
Try to solve the N Queens problem with SA of PyQUBO
Try to create a python environment with Visual Studio Code & WSL
Try to extract a character string from an image with Python3
Rails users try to create a simple blog engine with Django
I tried to create a list of prime numbers with python
[Go] Create a CLI command to change the extension of the image
I want to create a graph with wavy lines omitted in the middle with matplotlib (I want to manipulate the impression)
Create a summary table by product and time by processing the data extracted from a certain POS system
Learn accounting data and try to predict accounts from the content of the description when entering journals
How to create a large amount of test data in MySQL? ??
Create a poster with matplotlib to visualize multiplication tables that remember multiplication
From the introduction of JUMAN ++ to morphological analysis of Japanese with Python
Create a function to get the contents of the database in Go
Try to calculate the position of the transmitter from the radio wave propagation model with python [Wi-Fi, Beacon]
Try to solve the shortest path with Python + NetworkX + social data
From "drawing" to "writing" the configuration diagram: Try drawing the AWS configuration diagram with Diagrams
Try to create a Qiita article with REST API [Environmental preparation]
Create a REST API to operate dynamodb with the Django REST Framework
Create a compatibility judgment program with the random module of python.
[Completed version] Try to find out the number of residents in the town from the address list with Python
I want to solve the problem of memory leak when outputting a large number of images with Matplotlib
Upload data to s3 of aws with a command and update it, and delete the used data (on the way)