๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™”

pyecharts๋กœ ์‚ฐํฌ๋„ ๊ทธ๋ž˜ํ”„ ๊ทธ๋ฆฌ๊ธฐ

by ํฌ๋ฆฌ๋„ฅ์Šค์„๋ผ์ด์Šค 2023. 2. 12.

์•ˆ๋…•ํ•˜์„ธ์š” ํฌ๋ฆฌ๋„ฅ์Šค์„๋ผ์ด์Šค์ž…๋‹ˆ๋‹ค.

 

์˜ค๋Š˜์€ ๊ฐ„๋‹จํ•œ๊ฒŒ pyecharts ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ด์šฉํ•ด ์‚ฐํฌ๋„๋ฅผ ๋งŒ๋“ค์–ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

๋ฐ์ดํ„ฐ๋Š” 2022 ์‹œ์ฆŒ KBO ํŒ€์ˆœ์œ„๋ฅผ ์‚ฌ์šฉํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

2022 KBO ํŒ€์ˆœ์œ„

๋จผ์ œ ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ๋ฐ์ดํ„ฐ๋ฅผ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค.

# ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
import pandas as pd
from pyecharts.charts import Bar, Line, Scatter
from pyecharts import options as opts

 

๋‹ค์Œ ๋ช…๋ น์–ด๋กœ ์‚ฐํฌ๋„ ๊ทธ๋ž˜ํ”„๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

m = (
    Scatter()
    .add_xaxis(list(kbo["ํŒ€๋ช…"]))           # x๊ฐ’ -> ์ง์ ‘ ๊ฐ’์„ ์‚ฝ์ž…
    .add_yaxis("์Šน๋ฅ ", list(kbo["์Šน๋ฅ "]))   # y๊ฐ’
    .set_global_opts(
        title_opts=opts.TitleOpts(title="2022 KBO"),
        xaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),
        yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),
    )
    .render_notebook()
)

m

 

์‚ฐํฌ๋„

๋นจ๊ฐ„์ƒ‰์ด ๋ณ„๋กœ ์•ˆ ์˜ˆ์˜์‹œ๋ฉด, ๋‹ค์Œ๊ณผ ๊ฐ™์ด y๊ฐ’์˜ ๋ฒ”์œ„์— ๋”ฐ๋ผ ์ƒ‰์ƒ์˜ ๋ฒ”์œ„๋ฅผ ์ง€์ •ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์™ผ์ชฝ ํ•˜๋‹จ์˜ ์Šคํฌ๋กค ๋ถ€๋ถ„์„ ์กฐ์ ˆํ•ด ์ฃผ๋ฉด ํ•ด๋‹น ์˜์—ญ์˜ ๊ฐ’๋“ค๋งŒ ์ถœ๋ ฅ๋˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. 

m = (
    Scatter()
    .add_xaxis(list(kbo["ํŒ€๋ช…"]))
    .add_yaxis("์Šน๋ฅ ", list(kbo["์Šน๋ฅ "]))
    .set_global_opts(
        title_opts=opts.TitleOpts(title="2022 KBO"),
        xaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),
        yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),
        visualmap_opts=opts.VisualMapOpts(max_=1, min_ = 0) # max์™€ min์„ ์ž˜ ์„ค์ •ํ•ด ์ฃผ์„ธ์š”.
    )
    .render_notebook()
)

m

 

์ƒ‰์ƒ ์„ค์ •

 

๊ทธ๋ž˜ํ”„์— ์‹œ๊ฐ์  ํšจ๊ณผ๋ฅผ ๋” ์ฃผ๊ณ  ์‹ถ์œผ์‹œ๋‹ค๋ฉด, y๊ฐ’์— ๋”ฐ๋ผ ์ ์˜ ํฌ๊ธฐ๋ฅผ ๋‹ค๋ฅด๊ฒŒ ์ง€์ •ํ•ด ์ค„ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

m = (
    Scatter()
    .add_xaxis(list(kbo["ํŒ€๋ช…"]))
    .add_yaxis("์Šน๋ฅ ", list(kbo["์Šน๋ฅ "]))
    .set_global_opts(
        title_opts=opts.TitleOpts(title="2022 KBO"),
        xaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),
        yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),
        visualmap_opts=opts.VisualMapOpts(type_="size", max_=1, min_=0),
    )
    .render_notebook()
)

m

์ƒ‰์ƒ๊ณผ ์œ ์‚ฌํ•˜๊ฒŒ, ์™ผ์ชฝ ํ•˜๋‹จ์˜ ์Šคํฌ๋กค๋กœ ๋ฒ”์œ„๋ฅผ ์„ค์ •ํ•ด ์ค„ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

ํฌ๊ธฐ ์„ค์ •

๋˜ํ•œ, ์‚ฐํฌ๋„์— ๋‹ค์–‘ํ•œ ํšจ๊ณผ๋“ค์„ ์ถ”๊ฐ€ํ•ด ์ค„ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

(๊ทธ๋ž˜ํ”„์˜ ์ ์ด ์‚ฌ์ด๋ Œ์ฒ˜๋Ÿผ ์›€์ง์ž…๋‹ˆ๋‹ค.)

from pyecharts.charts import EffectScatter

m = (
    EffectScatter()  # ์ด ๋ถ€๋ถ„์ด Scatter()์—์„œ EffectScatter()๋กœ ๋ณ€๊ฒฝ
    .add_xaxis(list(kbo["ํŒ€๋ช…"]))
    .add_yaxis("์Šน๋ฅ ", list(kbo["์Šน๋ฅ "]))
    .set_global_opts(
        title_opts=opts.TitleOpts(title="2022 KBO"),
        xaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),
        yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),
    )
    .render_notebook()
)

m

ํšจ๊ณผ 1

์› ๋ชจ์–‘์ด ์งˆ๋ฆฌ์‹ ๋‹ค๋ฉด symbol ์˜ต์…˜์œผ๋กœ ๋‹ค์–‘ํ•œ ๋ชจ์–‘ ๋ณ€๊ฒฝ๋„ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

(ARROW ์™ธ์— DIAMOND, RECT, ROUND_RECT, TRIANGLE ์„ ์‚ฌ์šฉํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.)

m = (
    EffectScatter()
    .add_xaxis(list(kbo["ํŒ€๋ช…"]))
    .add_yaxis("์Šน๋ฅ ", list(kbo["์Šน๋ฅ "]), symbol=SymbolType.ARROW) 
    .set_global_opts(
        title_opts=opts.TitleOpts(title="2022 KBO"),
        xaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),
        yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),
    )
    .render_notebook()
)

m

 

์ด๋ฒˆ ์‚ฐํฌ๋„ ๊ทธ๋ž˜ํ”„๋Š” ์—ฌ๊ธฐ๊นŒ์ง€ ์ •๋ฆฌํ•ด ๋ณด์•˜์Šต๋‹ˆ๋‹ค.

 

๋‹ค์Œ์—๋„ ์žฌ๋ฐŒ๋Š” ์‹œ๊ฐํ™” ์ž๋ฃŒ๋ฅผ ๊ฐ€์ ธ์˜ค๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.