๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
์นดํ…Œ๊ณ ๋ฆฌ ์—†์Œ

Pyecharts-์‚ฐ์ ๋„

by ํฌ๋ฆฌ๋„ฅ์Šค์„๋ผ์ด์Šค 2021. 9. 1.

Pyechats-์‚ฐ์ ๋„

산점도(Scatter Plot)

์˜ค๋Š˜์€ ์‚ฐ์ ๋„๋ฅผ ๊ทธ๋ ค๋ณผ๋ ค๊ณ  ํ•œ๋‹ค.

In [40]:
# ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๊ฐ€์ ธ์˜ค๊ธฐ
import pandas as pd

import pyecharts.options as opts
from pyecharts.charts import Scatter

์ด๋ฒˆ์—๋Š” ๊ฐ€๋ณ๊ฒŒ ๊ทธ๋ ค๋ณผ ์˜ˆ์ •์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ฐ์ดํ„ฐ๋Š” ์ž‘์€ ๊ฑธ๋กœ ๊ฐ€์ ธ์™”๋‹ค.

๋‚˜๋ฌด์œ„ํ‚ค(https://namu.wiki/w/2021%20LoL%20Champions%20Korea%20Spring)์—์„œ 2021๋…„ LCK Spring, Summer์˜ PoG ์ ์ˆ˜ ๋ฐ์ดํ„ฐ๋‹ค.

image.png

๋‚˜๋Š” ์—‘์…€์— ํ•˜๋‚˜ํ•˜๋‚˜ ์ ์—ˆ๋‹ค.

In [3]:
data = pd.read_excel("LCK_PoG.xlsx")
In [4]:
data
Out[4]:
Name Summer PoG Points Spring PoG Points Team
0 Gori 1100 0 ๋†์‹ฌ
1 Canyon 1000 700 ๋‹ด์›
2 Faker 900 300 T1
3 Chovy 900 1000 ํ•œํ™”
4 Lava 900 400 ๋ธŒ๋ฆฌ์˜จ
5 Kiin 900 500 ์•„ํ”„๋ฆฌ์นด
6 Khan 800 800 ๋‹ด์›
7 Summit 800 200 ์ƒŒ๋“œ๋ฐ•์Šค
8 Bdd 700 600 ์  ์ง€
9 deokdam 700 400 ๋†์‹ฌ
In [14]:
# ๊ฐ ๋ฐ์ดํ„ฐ๋“ค์„ ๋ฆฌ์ŠคํŠธ ํ˜•ํƒœ๋กœ ๋ณ€๊ฒฝ
x = list(data["Name"])
y = list(data["Summer PoG Points"])
z = list(data["Spring PoG Points"])
team = list(data["Team"])

๊ธฐ๋ณธ์ ์ธ ์‚ฐ์ ๋„๋ฅผ ๊ทธ๋ฆฌ๋Š” ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

In [10]:
scatter = (
            Scatter()
            .add_xaxis(x)
            .add_yaxis("2021๋…„ LCK Summer PoG Points", y)
            .set_global_opts(title_opts = opts.TitleOpts(title="๋ฆฌ๊ทธ ์˜ค๋ธŒ ๋ ˆ์ „๋“œ"))
            .render_notebook() 
            )

scatter
Out[10]:

์—ฌ๊ธฐ์— ๊ฐ’๋ณ„๋กœ ๋‹ค๋ฅธ ์ƒ‰์ƒ์„ ์ง€์ •ํ•ด ์ค„ ์ˆ˜๋„ ์žˆ๋‹ค.

In [19]:
scatter = (
            Scatter()
            .add_xaxis(x)
            .add_yaxis("2021๋…„ LCK Summer PoG Points", y)
            .set_global_opts(title_opts = opts.TitleOpts(title="๋ฆฌ๊ทธ ์˜ค๋ธŒ ๋ ˆ์ „๋“œ"),
                             visualmap_opts = opts.VisualMapOpts(max_=1200))       # max_ ๊ฐ’์— ๋”ฐ๋ผ ์ƒ‰์ƒ์ด ๋‹ค๋ฅด๊ฒŒ ์ง€์ •๋œ๋‹ค.
            .render_notebook() 
            )

scatter
Out[19]:

๊ทธ๋ž˜ํ”„๊ฐ€ ์‹ฌ์‹ฌํ•ด ๋ณด์ธ๋‹ค๋ฉด ๊ฒฉ์ž๋ฅผ ์ถ”๊ฐ€ํ•ด ์ค„ ์ˆ˜๋„ ์žˆ๋‹ค.

In [12]:
scatter = (
            Scatter()
            .add_xaxis(x)
            .add_yaxis("2021๋…„ LCK Summer PoG Points", y)
            .set_global_opts(title_opts = opts.TitleOpts(title="๋ฆฌ๊ทธ ์˜ค๋ธŒ ๋ ˆ์ „๋“œ"),
                             xaxis_opts = opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),  # x์ถ• ๊ฒฉ์ž on
                             yaxis_opts = opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)))  # y์ถ• ๊ฒฉ์ž on
            .render_notebook() 
            )

scatter
Out[12]:

์‚ฐ์ ๋„๋ฅผ ์—ฌ๋Ÿฌ ๊ฐœ ๊ทธ๋ฆฌ๊ณ  ์‹ถ๋‹ค๋ฉด, ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„๋ฅผ ๊ทธ๋ ธ์„ ๋•Œ์ฒ˜๋Ÿผ ์ถ”๊ฐ€ํ•˜๊ธฐ๋งŒ ํ•˜๋ฉด ๋œ๋‹ค.

In [15]:
scatter = (
            Scatter()
            .add_xaxis(x)
            .add_yaxis("2021๋…„ LCK Summer PoG Points", y)
            .add_yaxis("2021๋…„ LCK Spring PoG Points", z)   # 2021๋…„ Spring ์‚ฐ์ ๋„๋ฅผ ์ถ”๊ฐ€
            .set_global_opts(title_opts = opts.TitleOpts(title="๋ฆฌ๊ทธ ์˜ค๋ธŒ ๋ ˆ์ „๋“œ"))
            .render_notebook() 
            )

scatter
Out[15]:

๊ฐ’๋“ค๋ณ„๋กœ ์ค‘์š”๋„๋ฅผ ๋‹ค๋ฅด๊ฒŒ ๋ณด์—ฌ์ค„ ์ˆ˜๋„ ์žˆ๋‹ค.

In [17]:
scatter = (
            Scatter()
            .add_xaxis(x)
            .add_yaxis("2021๋…„ LCK Summer PoG Points", y)
            .add_yaxis("2021๋…„ LCK Spring PoG Points", z)
            .set_global_opts(title_opts = opts.TitleOpts(title="๋ฆฌ๊ทธ ์˜ค๋ธŒ ๋ ˆ์ „๋“œ"),
                             visualmap_opts = opts.VisualMapOpts(type_="size", max_=1200, min_=200))   # max_, min_ ๊ฐ’์— ๋”ฐ๋ผ ํฌ๊ธฐ๊ฐ€ ๋ณ€๊ฒฝ
            .render_notebook() 
            )

scatter
Out[17]:
In [ ]: