๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™”

pyecharts๋กœ ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„ ๊ทธ๋ฆฌ๊ธฐ

ํฌ๋ฆฌ๋„ฅ์Šค์„๋ผ์ด์Šค 2023. 1. 26. 20:24

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

๋ณดํ†ต ํŒŒ์ด์ฌ์„ ์ด์šฉํ•ด ๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™”๋ฅผ ์ˆ˜ํ–‰ํ•  ๋•Œ๋Š” matplotlib๋‚˜ seaborn ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ด์šฉํ•˜์‹ค ๊ฒ๋‹ˆ๋‹ค.

๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋‹ค ๋ณด๋‹ˆ ์ €๋Š” ๋‹ค์†Œ ์งˆ๋ฆด ๋•Œ๋„ ์žˆ์—ˆ๋Š”๋ฐ์š”

๊ทธ๋ž˜์„œ ์ด๋ฒˆ์— ๋‹ค๋ค„ ๋ณผ ๋‚ด์šฉ์€ pyecharts ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ์–ด๋–ป๊ฒŒ ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š”์ง€

ํ•œ ๋ฒˆ ์ •๋ฆฌํ•ด ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

pyecharts - pyecharts.org

(๋” ๋‹ค์–‘ํ•œ Pyecharts ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๊ทธ๋ž˜ํ”„๋“ค์€ ์ด๊ณณ์—์„œ ์‚ดํŽด๋ณด์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.)


๋จผ์ € pyecharts๋ฅผ ์„ค์น˜ํ•ด ์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

pip install pyecharts

# ์ฃผํ”ผํ„ฐ๋…ธํŠธ๋ถ ์…€
!pip install pyecharts

์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ๋‹ค๋ฉด, ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ import ํ•ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

# ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ 
import pyecharts

# ๋ฒ„์ „ ํ™•์ธ
print("Pyecharts ๋ฒ„์ „ :", pyecharts.__version__)
๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ


pyecharts๋ฅผ ์‚ฌ์šฉํ•  ์ค€๋น„๊ฐ€ ๋˜์—ˆ๋‹ค๋ฉด ์ด์–ด์„œ ์‹œ๊ฐํ™”ํ•  ๋ฐ์ดํ„ฐ๋ฅผ ์ฐพ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

์ €๋Š” 2022๋…„ KBO ํŒ€ ์ˆœ์œ„ ์ •๋ณด๋ฅผ ์‚ฌ์šฉํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค(๋งํฌ).

KBO

๋งˆ์ง€๋ง‰ ํ™ˆ๊ณผ ๋ฐฉ๋ฌธ ์ปฌ๋Ÿผ์€ ์ œ์™ธํ•˜๊ณ  ๋ฐ์ดํ„ฐ๋ฅผ csv ํŒŒ์ผ๋กœ ๋งŒ๋“ค์–ด ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.
(์ธ์ฝ”๋”ฉ์ด ํ•„์š”ํ•ด cp949 ์˜ต์…˜์„ ์ถ”๊ฐ€ํ•ด์คฌ์Šต๋‹ˆ๋‹ค.)

# ํŒ๋‹ค์Šค ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ 
import pandas as pd
# ๊ทธ๋ฆฌ๊ณ  ์‹ถ์€ ๊ทธ๋ž˜ํ”„๋ฅผ ๋ถˆ๋Ÿฌ์˜จ๋‹ค.
from pyecharts.charts import Bar
# ๊ทธ๋ž˜ํ”„ ์˜ต์…˜์„ ์„ค์ •ํ•˜๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
from pyecharts import options as opts

# kbo csv ํŒŒ์ผ ์ฝ์–ด์˜ค๊ธฐ
kbo = pd.read_csv("./kbo.csv", encoding = "cp949")

# ๋ฐ์ดํ„ฐ ์ถœ๋ ฅ
kbo

kbo ๋ฐ์ดํ„ฐ๋ฅผ x์ถ•์€ ํŒ€, y์ถ•์€ ์Šน์œผ๋กœ ๋œ ๋ง‰๋Œ€๊ทธ๋ž˜ํ”„๋กœ ๊ทธ๋ ค๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

# ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€๊ฒฝ
x = list(kbo["ํŒ€๋ช…"])
y = list(kbo["์Šน"])

bar = (
    Bar()
    .add_xaxis(x)            # x์ถ•
    .add_yaxis("์Šน๋ฆฌ", y)    # y์ถ•
    .set_global_opts(title_opts = opts.TitleOpts(title = "2022๋…„ KBO ํŒ€์ˆœ์œ„",  # ์ œ๋ชฉ
                                                 subtitle = "์ •๊ทœ์‹œ์ฆŒ"))       # ์†Œ์ œ๋ชฉ
    .render_notebook()       # ์ฃผํ”ผํ„ฐ ๋…ธํŠธ๋ถ์— ๊ทธ๋ž˜ํ”„๋ฅผ ๋ฐ”๋กœ ์ถœ๋ ฅ
)

bar

์‹คํ–‰์‹œํ‚ค์‹œ๋ฉด ์•„๋ž˜ ์ด๋ฏธ์ง€์ฒ˜๋Ÿผ ๋ง‰๋Œ€๊ทธ๋ž˜ํ”„๊ฐ€ ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.

๋ง‰๋Œ€ ์œ„์— ๋งˆ์šฐ์Šค๋ฅผ ๊ฐ€์ ธ๊ฐ€๋ฉด ํ•ด๋‹น ๋ง‰๋Œ€์˜ ์ •๋ณด๋ฅผ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ง‰๋Œ€๊ทธ๋ž˜ํ”„

๋งŒ์•ฝ ๊ทธ๋ž˜ํ”„๋ฅผ html ํŒŒ์ผ๋กœ ์ €์žฅํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด .render_notebook()์„

render("๊ฒฝ๋กœ/ํŒŒ์ผ๋ช….html")์œผ๋กœ ๋ฐ”๊ฟ”์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

# ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€๊ฒฝ
x = list(kbo["ํŒ€๋ช…"])
y = list(kbo["์Šน"])

bar = (
    Bar()
    .add_xaxis(x)            # x์ถ•
    .add_yaxis("์Šน๋ฆฌ", y)    # y์ถ•
    .set_global_opts(title_opts = opts.TitleOpts(title = "2022๋…„ KBO ํŒ€์ˆœ์œ„",  # ์ œ๋ชฉ
                                                 subtitle = "์ •๊ทœ์‹œ์ฆŒ"))       # ์†Œ์ œ๋ชฉ
    .render("kbo_bar_graph.html")     # ๊ทธ๋ž˜ํ”„๋ฅผ html๋กœ ์ €์žฅ
)
html ํŒŒ์ผ

๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„ ์œ„์˜ ์ˆซ์ž๋ฅผ ์ถœ๋ ฅํ•˜๊ณ  ์‹ถ์ง€ ์•Š๋‹ค๋ฉด add_yaxis์—์„œ label_opts ์˜ต์…˜์„ False๋กœ ์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

# ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€๊ฒฝ
x = list(kbo["ํŒ€๋ช…"])
y = list(kbo["์Šน"])

bar = (
    Bar()
    .add_xaxis(x)            # x์ถ•
    .add_yaxis("์Šน๋ฆฌ", y, label_opts = False)  # label_opts = False ์˜ต์…˜์œผ๋กœ ๋ฐ์ดํ„ฐ ์ถœ๋ ฅ์„ off
    .set_global_opts(title_opts = opts.TitleOpts(title = "2022๋…„ KBO ํŒ€์ˆœ์œ„",  # ์ œ๋ชฉ
                                                 subtitle = "์ •๊ทœ์‹œ์ฆŒ"))       # ์†Œ์ œ๋ชฉ
    .render_notebook()       # ์ฃผํ”ผํ„ฐ ๋…ธํŠธ๋ถ์— ๊ทธ๋ž˜ํ”„๋ฅผ ๋ฐ”๋กœ ์ถœ๋ ฅ
)

bar
๊ทธ๋ž˜ํ”„ ์œ„ ์ˆซ์ž ์—†์• ๊ธฐ

๋นจ๊ฐ„์ƒ‰์ด ๋„ˆ๋ฌด ๋ถ€๋‹ด์Šค๋Ÿฌ์›Œ ๋‹ค๋ฅธ ์ƒ‰์œผ๋กœ ๋ฐ”๊พธ๊ณ  ์‹ถ๋‹ค๋ฉด color ์˜ต์…˜์„ ์„ค์ •ํ•ด ์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

# ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€๊ฒฝ
x = list(kbo["ํŒ€๋ช…"])
y = list(kbo["์Šน"])

bar = (
    Bar()
    .add_xaxis(x)            # x์ถ•
    .add_yaxis("์Šน๋ฆฌ", y, label_opts = False, color = "CornflowerBlue")  # color ์˜ต์…˜์œผ๋กœ ์ƒ‰์ƒ์„ ๋ณ€๊ฒฝ
    .set_global_opts(title_opts = opts.TitleOpts(title = "2022๋…„ KBO ํŒ€์ˆœ์œ„",  # ์ œ๋ชฉ
                                                 subtitle = "์ •๊ทœ์‹œ์ฆŒ"))       # ์†Œ์ œ๋ชฉ
    .render_notebook()       # ์ฃผํ”ผํ„ฐ ๋…ธํŠธ๋ถ์— ๊ทธ๋ž˜ํ”„๋ฅผ ๋ฐ”๋กœ ์ถœ๋ ฅ
)

bar

๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„ ์ƒ‰์ƒ ๋ณ€๊ฒฝ

๋งŒ์•ฝ x์ถ•๊ณผ y์ถ•์— ๋Œ€ํ•œ ์ด๋ฆ„์„ ๋„ฃ๊ณ  ์‹ถ๋‹ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์˜ต์…˜์„ ์ถ”๊ฐ€ํ•ด ์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

# ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€๊ฒฝ
x = list(kbo["ํŒ€๋ช…"])
y = list(kbo["์Šน"])

bar = (
    Bar()
    .add_xaxis(x)            # x์ถ•
    .add_yaxis("์Šน๋ฆฌ", y, label_opts = False, color = "LightCoral")  # color ์˜ต์…˜์œผ๋กœ ์ƒ‰์ƒ์„ ๋ณ€๊ฒฝ
    .set_global_opts(title_opts = opts.TitleOpts(title = "2022๋…„ KBO ํŒ€์ˆœ์œ„", subtitle = "์ •๊ทœ์‹œ์ฆŒ"),
                                        xaxis_opts = opts.AxisOpts(name = "์ฐธ์—ฌ ํŒ€๋ช…"),  # X์ถ• ์ด๋ฆ„
                                        yaxis_opts = opts.AxisOpts(name = "์Šน๋ฆฌ ํšŸ์ˆ˜"))  # Y์ถ• ์ด๋ฆ„
    .render_notebook()       # ์ฃผํ”ผํ„ฐ ๋…ธํŠธ๋ถ์— ๊ทธ๋ž˜ํ”„๋ฅผ ๋ฐ”๋กœ ์ถœ๋ ฅ
)

bar
x์ถ•๊ณผ y์ถ•์— ์ด๋ฆ„ ๋„ฃ๊ธฐ

๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๋” ๋„ฃ๊ณ  ์‹ถ๋‹ค๋ฉด y์ถ•์— ๋ˆˆ๊ธˆ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

# ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€๊ฒฝ
x = list(kbo["ํŒ€๋ช…"])
y = list(kbo["์Šน"])

bar = (
    Bar()
    .add_xaxis(x)            # x์ถ•
    .add_yaxis("์Šน๋ฆฌ", y, label_opts = False, color = "LightCoral")  # color ์˜ต์…˜์œผ๋กœ ์ƒ‰์ƒ์„ ๋ณ€๊ฒฝ
    .set_global_opts(title_opts = opts.TitleOpts(title = "2022๋…„ KBO ํŒ€์ˆœ์œ„", subtitle = "์ •๊ทœ์‹œ์ฆŒ"),
                                        xaxis_opts = opts.AxisOpts(name = "์ฐธ์—ฌ ํŒ€๋ช…"),  # X์ถ• ์ด๋ฆ„
                                        yaxis_opts = opts.AxisOpts(name = "์Šน๋ฆฌ ํšŸ์ˆ˜",
                                                                   axislabel_opts = opts.LabelOpts(formatter="{value} (๊ฒฝ๊ธฐ)"))) # Y์ถ• ๋ˆˆ๊ธˆ ํฌ๋งท
    .render_notebook()       # ์ฃผํ”ผํ„ฐ ๋…ธํŠธ๋ถ์— ๊ทธ๋ž˜ํ”„๋ฅผ ๋ฐ”๋กœ ์ถœ๋ ฅ
)

bar

๊ฒฐ๊ณผ๋ฅผ ๋ณด์‹œ๋ฉด ์™ผ์ชฝ y์ถ•์— '๊ฒฝ๊ธฐ'๋ผ๋Š” ๋ฌธ๊ตฌ๊ฐ€ ์ถ”๊ฐ€๋œ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

y์ถ• ๋ˆˆ๊ธˆ ๋‹จ์œ„

๋‹ค์Œ์€ ๊ทธ๋ž˜ํ”„์— ์คŒ/์•„์›ƒ ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•˜๋Š” ์˜ต์…˜์ž…๋‹ˆ๋‹ค.

# ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€๊ฒฝ
x = list(kbo["ํŒ€๋ช…"])
y = list(kbo["์Šน"])

bar = (
    Bar()
    .add_xaxis(x)            # x์ถ•
    .add_yaxis("์Šน๋ฆฌ", y, label_opts = False, color = "LightCoral")  # color ์˜ต์…˜์œผ๋กœ ์ƒ‰์ƒ์„ ๋ณ€๊ฒฝ
    .set_global_opts(title_opts = opts.TitleOpts(title = "2022๋…„ KBO ํŒ€์ˆœ์œ„", subtitle = "์ •๊ทœ์‹œ์ฆŒ"),
                                        xaxis_opts = opts.AxisOpts(name = "์ฐธ์—ฌ ํŒ€๋ช…"),  # X์ถ• ์ด๋ฆ„
                                        yaxis_opts = opts.AxisOpts(name = "์Šน๋ฆฌ ํšŸ์ˆ˜",
                                                                   axislabel_opts = opts.LabelOpts(formatter="{value} (๊ฒฝ๊ธฐ)")),
                                        datazoom_opts=[opts.DataZoomOpts(), opts.DataZoomOpts(type_="inside")])  # ๊ทธ๋ž˜ํ”„๋ฅผ ์คŒ/์•„์›ƒ ํ•  ์ˆ˜ ์žˆ๋‹ค
    .render_notebook()       # ์ฃผํ”ผํ„ฐ ๋…ธํŠธ๋ถ์— ๊ทธ๋ž˜ํ”„๋ฅผ ๋ฐ”๋กœ ์ถœ๋ ฅ
)

bar
์คŒ/์•„์›ƒ

๊ทธ๋ž˜ํ”„ ์˜ค๋ฅธ์ชฝ ์ƒ๋‹จ์— ํ•„์š”ํ•œ ๊ธฐ๋Šฅ์„ ๋‹ด์€ ํˆด๋ฐ•์Šค๋ฅผ ๋งŒ๋“œ๋Š” ์˜ต์…˜์ž…๋‹ˆ๋‹ค.

(๋‹ค๋งŒ, ํˆด ๊ธฐ๋Šฅ๋“ค์ด ์ค‘๊ตญ์–ด๋กœ ์ถœ๋ ฅ๋˜๊ณ  ์žˆ๋„ค์š”.)

# ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€๊ฒฝ
x = list(kbo["ํŒ€๋ช…"])
y = list(kbo["์Šน"])

bar = (
    Bar()
    .add_xaxis(x)            # x์ถ•
    .add_yaxis("์Šน๋ฆฌ", y, label_opts = False, color = "LightCoral")  # color ์˜ต์…˜์œผ๋กœ ์ƒ‰์ƒ์„ ๋ณ€๊ฒฝ
    .set_global_opts(title_opts = opts.TitleOpts(title = "2022๋…„ KBO ํŒ€์ˆœ์œ„", subtitle = "์ •๊ทœ์‹œ์ฆŒ"),
                                        xaxis_opts = opts.AxisOpts(name = "์ฐธ์—ฌ ํŒ€๋ช…"),  # X์ถ• ์ด๋ฆ„
                                        yaxis_opts = opts.AxisOpts(name = "์Šน๋ฆฌ ํšŸ์ˆ˜",
                                                                   axislabel_opts = opts.LabelOpts(formatter="{value} (๊ฒฝ๊ธฐ)")),
                                        datazoom_opts=[opts.DataZoomOpts(), opts.DataZoomOpts(type_="inside")],
                                        toolbox_opts = opts.ToolboxOpts())          # ๊ทธ๋ž˜ํ”„ ์˜ค๋ฅธ์ชฝ ์œ„์— ํˆด๋ฐ•์Šค๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.
    .render_notebook()       # ์ฃผํ”ผํ„ฐ ๋…ธํŠธ๋ถ์— ๊ทธ๋ž˜ํ”„๋ฅผ ๋ฐ”๋กœ ์ถœ๋ ฅ
)

bar

์ด๋ฒˆ์—๋Š” ์Šน๋ฆฌ์™€ ํŒจ๋ฐฐ๋ฅผ ๊ฐ™์ด ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„๋กœ ํ‘œํ˜„ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

# ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€๊ฒฝ
x = list(kbo["ํŒ€๋ช…"])
y = list(kbo["์Šน"])
z = list(kbo["ํŒจ"])  # ํŒจ ์ปฌ๋Ÿผ์„ ๋ฆฌ์ŠคํŠธ๋กœ ์ƒ์„ฑ

double_bar = (
    Bar()
    .add_xaxis(x)        
    .add_yaxis("์Šน๋ฆฌ", y)
    .add_yaxis("ํŒจ๋ฐฐ", z)    # z๋ฅผ y์ถ•์— ์ถ”๊ฐ€
    .set_global_opts(title_opts = opts.TitleOpts(title = "2022๋…„ KBO ํŒ€์ˆœ์œ„",  # ์ œ๋ชฉ
                                                 subtitle = "์ •๊ทœ์‹œ์ฆŒ"))       # ์†Œ์ œ๋ชฉ
    .render_notebook()
)

double_bar

์ƒ๋‹จ ์ค‘์•™์˜ ์Šน๋ฆฌ/ํŒจ๋ฐฐ๋ฅผ ๋ˆŒ๋Ÿฌ์ฃผ์‹œ๋ฉด ํ•ด๋‹น ํ•ญ๋ชฉ์€ ๊ทธ๋ž˜ํ”„์—์„œ ์‚ฌ๋ผ์ง€๋Š” ๊ฒƒ์„ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„

๋ง‰๋Œ€ ์‚ฌ์ด์˜ ๊ฐ„๊ฒฉ์„ ์กฐ์ •ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด gap ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

# ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€๊ฒฝ
x = list(kbo["ํŒ€๋ช…"])
y = list(kbo["์Šน"])
z = list(kbo["ํŒจ"])

double_bar = (
    Bar()
    .add_xaxis(x)        
    .add_yaxis("์Šน๋ฆฌ", y, gap="0%")  # ๋ง‰๋Œ€ ๊ฐ„๊ฒฉ ์กฐ์ •
    .add_yaxis("ํŒจ๋ฐฐ", z, gap="0%")  # ๋ง‰๋Œ€ ๊ฐ„๊ฒฉ ์กฐ์ •
    .set_global_opts(title_opts = opts.TitleOpts(title = "2022๋…„ KBO ํŒ€์ˆœ์œ„",  # ์ œ๋ชฉ
                                                 subtitle = "์ •๊ทœ์‹œ์ฆŒ"))       # ์†Œ์ œ๋ชฉ
    .render_notebook()
)

double_bar
gap์ด 0% ์ผ ๋•Œ
gap์ด 100% ์ผ ๋•Œ

๋ˆ„์  ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„๋กœ ํ‘œํ˜„ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด stack ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

# ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€๊ฒฝ
x = list(kbo["ํŒ€๋ช…"])
y = list(kbo["์Šน"])
z = list(kbo["ํŒจ"])
a = list(kbo["๋ฌด"])

double_bar = (
    Bar()
    .add_xaxis(x)        
    .add_yaxis("์Šน๋ฆฌ", y, label_opts = False, color = "LightBlue", stack="stack") # stack ์˜ต์…˜
    .add_yaxis("ํŒจ๋ฐฐ", z, label_opts = False, color = "LemonChiffon", stack="stack") # stack ์˜ต์…˜
    .add_yaxis("๋ฌด", a, label_opts = False, color = "LightCoral", stack="stack") # stack ์˜ต์…˜
    .set_global_opts(title_opts = opts.TitleOpts(title = "2022๋…„ KBO ํŒ€์ˆœ์œ„",
                                                 subtitle = "์ •๊ทœ์‹œ์ฆŒ"))   
    .render_notebook()
)

double_bar
๋ˆ„์  ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„

์˜ค๋Š˜์€ ์—ฌ๊ธฐ๊นŒ์ง€ ์ค€๋น„ํ–ˆ์Šต๋‹ˆ๋‹ค.

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