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

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

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

Untitled

Pyecharts

๊ตฌ๊ธ€์— Pyecharts๋ฅผ ๊ฒ€์ƒ‰ํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ŠคํŽ€์ง€๋ฐฅ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค. image.png

Pyecharts๋ฅผ ์ด์šฉํ•ด ๊ทธ๋ฆด ์ˆ˜ ์žˆ๋Š” ๊ทธ๋ž˜ํ”„๋“ค์ด ๊ถ๊ธˆํ•˜๋‹ค๋ฉด https://github.com/pyecharts/pyecharts-gallery ์ด๊ณณ์„ ๋ฐฉ๋ฌธํ•ด์„œ ์‚ดํŽด ๋ณด๋ฉด ๋œ๋‹ค.

์ด ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ์ด์œ ๋Š” ๋‹จ์ˆœํ•˜๋‹ค. ๋‚˜์ค‘์— ์‰ฝ๊ฒŒ ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„๋ฅผ ๊ทธ๋ฆฌ๊ณ  ์‹ถ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

In [ ]:
# pyecharts ์„ค์น˜๋Š” ๋น„๊ต์  ์‰ฝ๋‹ค.
!pip install pyecharts
In [1]:
# pyecharts ๋ฒ„์ „ ํ™•์ธํ•˜๊ธฐ
import pyecharts

print("Pyecharts ๋ฒ„์ „ :", pyecharts.__version__)
Pyecharts ๋ฒ„์ „ : 1.9.0

๋จผ์ € ๊ทธ๋ž˜ํ”„๋ฅผ ๊ทธ๋ฆฌ๊ธฐ ์ „์— ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ๋Š” ํ†ต๊ณ„์ฒญ(https://kosis.kr/index/index.do)์˜ ์ธ๊ตฌ ์ด ์กฐ์‚ฌ ๋ฐ์ดํ„ฐ๋ฅผ ์ด์šฉํ–ˆ๋‹ค.

image.png

์ด ํ†ต๊ณ„์—์„œ ๋‚˜๋Š” 2020๋…„ ์ด์ธ๊ตฌ, ๋‚จ์ž์ธ๊ตฌ, ์—ฌ์ž์ธ๊ตฌ๋ฅผ ์‹œ๋„๋ณ„๋กœ ๊ฐ€์ ธ์™”๋‹ค. image.png

In [2]:
# ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
import pandas as pd
import numpy as np

# ๊ทธ๋ฆฌ๊ณ  ์‹ถ์€ ๊ทธ๋ž˜ํ”„๋ฅผ ๋ถˆ๋Ÿฌ์˜จ๋‹ค.
from pyecharts.charts import Bar, Line

# ๊ทธ๋ž˜ํ”„ ์˜ต์…˜์„ ์„ค์ •ํ•˜๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
from pyecharts import options as opts
In [3]:
# ์—‘์…€ ๋ฐ์ดํ„ฐ๋ฅผ ๊ทธ๋ƒฅ ๊ฐ€์ ธ์˜ค๋ฉด 0๋ฒˆ์งธ ํ–‰์—๋„ ์ปฌ๋Ÿผ์˜ ์ด๋ฆ„์ด ๋“ค์–ด๊ฐ€๊ธฐ ๋•Œ๋ฌธ์— ์˜ต์…˜์œผ๋กœ header = 1์„ ์ถ”๊ฐ€ํ•œ๋‹ค.
data = pd.read_excel("2020๋…„ ์ธ๊ตฌ.xlsx", header = 1)
In [4]:
data.head(5)
Out[4]:
ํ–‰์ •๊ตฌ์—ญ๋ณ„(์๋ฉด๋™) ์ด์ธ๊ตฌ (๋ช…) ๋‚จ์ž (๋ช…) ์—ฌ์ž (๋ช…)
0 ์ „๊ตญ 51829136 25915207 25913929
1 ์„œ์šธํŠน๋ณ„์‹œ 9586195 4647733 4938462
2 ๋ถ€์‚ฐ๊ด‘์—ญ์‹œ 3349016 1638751 1710265
3 ๋Œ€๊ตฌ๊ด‘์—ญ์‹œ 2410700 1190271 1220429
4 ์ธ์ฒœ๊ด‘์—ญ์‹œ 2945454 1477064 1468390

Pyecharts를 이용할 때 중요한 점은 그래프에 전달할 데이터는 꼭 리스트로 변경해서 전달해야 한다.

In [55]:
# ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€๊ฒฝ
x = list(data["ํ–‰์ •๊ตฌ์—ญ๋ณ„(์๋ฉด๋™)"])
y = list(data["์ด์ธ๊ตฌ (๋ช…)"])
In [8]:
bar = (
    Bar()
    .add_xaxis(x)            # x์ถ•
    .add_yaxis("์ด์ธ๊ตฌ", y)  # y์ถ•
    .set_global_opts(title_opts = opts.TitleOpts(title = "2020๋…„ ๋Œ€ํ•œ๋ฏผ๊ตญ ์ด์ธ๊ตฌ",    # ์ œ๋ชฉ
                                                 subtitle = "์ธ๊ตฌ์ด์กฐ์‚ฌ ์ „์ˆ˜๋ถ€๋ฌธ"))   # ์ œ๋ชฉ ์•„๋ž˜ ์†Œ์ œ๋ชฉ
    .render_notebook()   # ์ฃผํ”ผํ„ฐ ๋…ธํŠธ๋ถ์— ๊ทธ๋ž˜ํ”„๋ฅผ ์ถœ๋ ฅ
)

bar
Out[8]:

๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„๋Š” ์˜ˆ์˜๊ฒŒ ๊ทธ๋ ค์กŒ์ง€๋งŒ ๊ทธ๋ž˜ํ”„ ์œ„์— ์ถœ๋ ฅ๋˜๋Š” ๋ฐ์ดํ„ฐ๊ฐ€ ์กฐ๊ธˆ ๊ฑฐ์Šฌ๋ฆฐ๋‹ค.

In [7]:
bar = (
    Bar()
    .add_xaxis(x)                               
    .add_yaxis("์ด์ธ๊ตฌ", y, label_opts = False)  # label_opts = False ์˜ต์…˜์œผ๋กœ ๋ฐ์ดํ„ฐ ์ถœ๋ ฅ์„ offํ–ˆ๋‹ค.
    .set_global_opts(title_opts = opts.TitleOpts(title = "2020๋…„ ๋Œ€ํ•œ๋ฏผ๊ตญ ์ด์ธ๊ตฌ", 
                                                 subtitle = "์ธ๊ตฌ์ด์กฐ์‚ฌ ์ „์ˆ˜๋ถ€๋ฌธ"))
    .render_notebook()  # ๊ทธ๋ž˜ํ”„๋ฅผ HTML๋กœ ๋‹ค์šด๋ฐ›๊ณ  ์‹ถ๋‹ค๋ฉด bar.render("boxplot_base.html")๋กœ ๋ฐ”๊ฟ”์„œ ์‹คํ–‰ํ•˜๋ฉด ๋œ๋‹ค.
)

bar
Out[7]:

๋‚ด๊ฐ€ ์›ํ•˜๋Š” ํ˜•ํƒœ๋กœ ๊ทธ๋ž˜ํ”„๊ฐ€ ๊ทธ๋ ค์กŒ์ง€๋งŒ ๋นจ๊ฐ„์ƒ‰์€ ์ข€ ๋ถ€๋‹ด์Šค๋Ÿฝ๋‹ค. ๊ทธ๋ž˜์„œ ์ƒ‰์„ ๋ณ€๊ฒฝํ•˜์ž.

http://www.w3big.com/ko/tags/html-colorname.html ์ด๊ณณ์—์„œ HTML ์ƒ‰์ƒ์„ ๋ณด๊ณ  ๋ง˜์— ๋“œ๋Š” ์ƒ‰์ƒ์„ ์„ ํƒํ–ˆ๋‹ค.

In [10]:
bar = (
    Bar()
    .add_xaxis(x)                               
    .add_yaxis("์ด์ธ๊ตฌ", y, label_opts = False, color = "Teal")   # color ์˜ต์…˜์— ์›ํ•˜๋Š” ์ƒ‰์ƒ ์ด๋ฆ„์„ ๋„ฃ์œผ๋ฉด ๋œ๋‹ค.
    .set_global_opts(title_opts = opts.TitleOpts(title = "2020๋…„ ๋Œ€ํ•œ๋ฏผ๊ตญ ์ด์ธ๊ตฌ", 
                                                 subtitle = "์ธ๊ตฌ์ด์กฐ์‚ฌ ์ „์ˆ˜๋ถ€๋ฌธ"))
    .render_notebook()
)

bar
Out[10]:

์ฒ˜์Œ ๊ทธ๋ž˜ํ”„๋ฅผ ๋ณด๋ฉด x์ถ•๊ณผ y์ถ•์ด ๋ฌด์—‡์„ ์˜๋ฏธํ•˜๋Š”์ง€ ์‰ฝ๊ฒŒ ์ดํ•ดํ•˜๊ธฐ ์–ด๋ ค์šด ๊ฒฝ์šฐ๋“ค๋„ ์žˆ๋‹ค. ๊ทธ๋Ÿด ๋•Œ๋Š” x์ถ•๊ณผ y์ถ•์— ์ด๋ฆ„์„ ์„ค์ •ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

In [71]:
bar = (
    Bar()
    .add_xaxis(x)                               
    .add_yaxis("์ด์ธ๊ตฌ", y, label_opts = False, color = "Teal")   # color ์˜ต์…˜์— ์›ํ•˜๋Š” ์ƒ‰์ƒ ์ด๋ฆ„์„ ๋„ฃ์œผ๋ฉด ๋œ๋‹ค.
    .set_global_opts(title_opts = opts.TitleOpts(title = "2020๋…„ ๋Œ€ํ•œ๋ฏผ๊ตญ ์ด์ธ๊ตฌ"), # ์†Œ์ œ๋ชฉ์ด๋ž‘ Y์ถ• ์ œ๋ชฉ์ด๋ž‘ ๊ฒน์ณ์„œ ์ œ๊ฑฐ
                    yaxis_opts = opts.AxisOpts(name = "Y์ถ• ์ œ๋ชฉ"),  # X์ถ• ์ด๋ฆ„
                    xaxis_opts = opts.AxisOpts(name = "X์ถ• ์ œ๋ชฉ"),  # Y์ถ• ์ด๋ฆ„
    )
    .render_notebook()
)

bar
Out[71]:

์œ„์™€ ๋น„์Šทํ•œ ์ด์œ ๋กœ ์‰ฝ๊ฒŒ ๊ทธ๋ž˜ํ”„๋ฅผ ์ดํ•ด์‹œํ‚ค๊ธฐ ์œ„ํ•ด y์ถ• ๋ˆˆ๊ธˆ์˜ ๋‹จ์œ„๋ฅผ ๋„ฃ์–ด์ค„ ์ˆ˜๋„ ์žˆ๋‹ค.

In [74]:
bar = (
    Bar()
    .add_xaxis(x)                               
    .add_yaxis("์ด์ธ๊ตฌ", y, label_opts = False, color = "Teal")
    .set_global_opts(title_opts = opts.TitleOpts(title = "2020๋…„ ๋Œ€ํ•œ๋ฏผ๊ตญ ์ด์ธ๊ตฌ"),
                     yaxis_opts = opts.AxisOpts(axislabel_opts = opts.LabelOpts(formatter="{value} (๋ช…)")), # Y์ถ• ๋ˆˆ๊ธˆ ํฌ๋งท
    )
    .render_notebook()
)

bar
Out[74]:

๋‚ด๊ฐ€ ์›ํ•˜๋Š” ๋ง‰๋Œ€๊ทธ๋ž˜ํ”„๋งŒ ๋ณด๊ณ  ์‹ถ๋‹ค๋˜๊ฐ€, ์ถฉ์ฒญ๋‚จ๋„๋ž‘ ์ „๋ผ๋‚จ๋„๋งŒ ๋น„๊ตํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ์— ๊ทธ๋ž˜ํ”„ ์คŒ/์•„์›ƒ ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค.

In [37]:
bar = (
    Bar()
    .add_xaxis(x)                               
    .add_yaxis("์ด์ธ๊ตฌ", y, label_opts = False, color = "Teal")  
    .set_global_opts(title_opts = opts.TitleOpts(title = "2020๋…„ ๋Œ€ํ•œ๋ฏผ๊ตญ ์ด์ธ๊ตฌ", 
                                                 subtitle = "์ธ๊ตฌ์ด์กฐ์‚ฌ ์ „์ˆ˜๋ถ€๋ฌธ"),
                    datazoom_opts=[opts.DataZoomOpts(), opts.DataZoomOpts(type_="inside")])  # ๊ทธ๋ž˜ํ”„๋ฅผ ์คŒ/์•„์›ƒ ํ•  ์ˆ˜ ์žˆ๋‹ค.
    .render_notebook()
)

bar
Out[37]:
In [67]:
bar = (
    Bar()
    .add_xaxis(x)                               
    .add_yaxis("์ด์ธ๊ตฌ", y, label_opts = False, color = "Teal")  
    .set_global_opts(title_opts = opts.TitleOpts(title = "2020๋…„ ๋Œ€ํ•œ๋ฏผ๊ตญ ์ด์ธ๊ตฌ", 
                                                 subtitle = "์ธ๊ตฌ์ด์กฐ์‚ฌ ์ „์ˆ˜๋ถ€๋ฌธ"),
                     toolbox_opts = opts.ToolboxOpts(),          # ๊ทธ๋ž˜ํ”„ ์˜ค๋ฅธ์ชฝ ์œ„์— ํˆด๋ฐ•์Šค๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.
                     legend_opts=opts.LegendOpts(is_show=False))
    .render_notebook()
)

bar
Out[67]:

๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„์— ์ง€๋„์ฒ˜๋Ÿผ ๋งˆํฌํฌ์ธํŠธ๋„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค.

In [57]:
bar = (
    Bar()
    .add_xaxis(x)                               
    .add_yaxis("์ด์ธ๊ตฌ", y, label_opts = False, color = "Teal", 
               markpoint_opts = opts.MarkPointOpts(data = [opts.MarkPointItem(name = "๋ถ€์‚ฐ",       # ๋งˆํฌํฌ์ธํŠธ ์ด๋ฆ„
                                                                              coord=[x[2], y[2]],  # ๋งˆํฌํฌ์ธํŠธ ์œ„์น˜ 
                                                                              value="๋ถ€์‚ฐ")]))     # ๋งˆํฌํฌ์ธํŠธ ๊ฐ’
    .set_global_opts(title_opts = opts.TitleOpts(title = "2020๋…„ ๋Œ€ํ•œ๋ฏผ๊ตญ ์ด์ธ๊ตฌ", 
                                                 subtitle = "์ธ๊ตฌ์ด์กฐ์‚ฌ ์ „์ˆ˜๋ถ€๋ฌธ"))
    .render_notebook()
)

bar
Out[57]:

์ด๋ฒˆ์—” ๋‚จ์ž ์ธ๊ตฌ์™€ ์—ฌ์ž ์ธ๊ตฌ๋ฅผ ํ•œ ๊ทธ๋ž˜ํ”„์— ํ‘œํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.

In [11]:
# ๋จผ์ € ๋ฆฌ์ŠคํŠธ๋กœ ๋ฐ์ดํ„ฐ ์ง€์ •
man = list(data["๋‚จ์ž (๋ช…)"])
woman = list(data["์—ฌ์ž (๋ช…)"])
In [41]:
# ์ฝ”๋“œ๋Š” ๊ฐ„๋‹จํ•˜๋‹ค. bar ๊ทธ๋ž˜ํ”„๋ฅผ ํ•˜๋‚˜ ๋” ์ถ”๊ฐ€ํ•˜๋ฉด ๋œ๋‹ค.
double_bar = (
    Bar()
    .add_xaxis(x)   # x์ถ• 
    .add_yaxis("๋‚จ์ž ์ธ๊ตฌ", man, label_opts = False, color = "SlateBlue")  # y์ถ•1
    .add_yaxis("์—ฌ์ž ์ธ๊ตฌ", woman, label_opts = False, color = "HotPink")    # y์ถ•2
    .set_global_opts(title_opts = opts.TitleOpts(title = "2020๋…„ ๋Œ€ํ•œ๋ฏผ๊ตญ ์„ฑ๋ณ„ ์ธ๊ตฌ", 
                                                 subtitle = "์ธ๊ตฌ์ด์กฐ์‚ฌ ์ „์ˆ˜๋ถ€๋ฌธ"))
    .render_notebook()
)

double_bar
Out[41]:
In [42]:
double_bar = (
    Bar()
    .add_xaxis(x)   # x์ถ• 
    .add_yaxis("๋‚จ์ž ์ธ๊ตฌ", man, label_opts = False, color = "SlateBlue", gap="0%")  # gap ์˜ต์…˜์œผ๋กœ ๋ง‰๋Œ€๊ทธ๋ž˜ํ”„ ์‚ฌ์ด ๊ฐ„๊ฒฉ์„ ์กฐ์ ˆํ•œ๋‹ค.
    .add_yaxis("์—ฌ์ž ์ธ๊ตฌ", woman, label_opts = False, color = "HotPink", gap="0%") 
    .set_global_opts(title_opts = opts.TitleOpts(title = "2020๋…„ ๋Œ€ํ•œ๋ฏผ๊ตญ ์„ฑ๋ณ„ ์ธ๊ตฌ", 
                                                 subtitle = "์ธ๊ตฌ์ด์กฐ์‚ฌ ์ „์ˆ˜๋ถ€๋ฌธ"))
    .render_notebook()
)

double_bar
Out[42]:

๋‘ ๊ทธ๋ž˜ํ”„๋ฅผ ์—ฐ๋‹ฌ์•„ ๋ณด๋Š”๊ฒŒ ์•„๋‹ˆ๋ผ ๋ˆ„์ ์œผ๋กœ ๋ณด๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์˜ต์…˜์„ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉฐ ๋œ๋‹ค.

In [65]:
double_bar = (
    Bar()
    .add_xaxis(x)   # x์ถ• 
    .add_yaxis("๋‚จ์ž ์ธ๊ตฌ", man, label_opts = False, color = "SlateBlue", stack="stack")  # stack ์˜ต์…˜์œผ๋กœ ๋ˆ„์ ๊ทธ๋ž˜ํ”„๋ฅผ ๊ทธ๋ฆด ์ˆ˜ ์žˆ๋‹ค.
    .add_yaxis("์—ฌ์ž ์ธ๊ตฌ", woman, label_opts = False, color = "HotPink", stack="stack") 
    .set_global_opts(title_opts = opts.TitleOpts(title = "2020๋…„ ๋Œ€ํ•œ๋ฏผ๊ตญ ์„ฑ๋ณ„ ์ธ๊ตฌ", 
                                                 subtitle = "์ธ๊ตฌ์ด์กฐ์‚ฌ ์ „์ˆ˜๋ถ€๋ฌธ"))
    .render_notebook()
)

double_bar
Out[65]:
In [15]:
# 3๊ฐœ๋„ ๊ทธ๋ฆด ์ˆ˜ ์žˆ๋‚˜ ํ•ด๋ดค๋‹ค.
triple_bar = (
    Bar()
    .add_xaxis(x)   # x์ถ• 
    .add_yaxis("์ด์ธ๊ตฌ", y, label_opts = False)        # y์ถ•1
    .add_yaxis("๋‚จ์ž ์ธ๊ตฌ", man, label_opts = False)   # y์ถ•2
    .add_yaxis("์—ฌ์ž ์ธ๊ตฌ", woman, label_opts = False) # y์ถ•3
    .set_global_opts(title_opts = opts.TitleOpts(title = "2020๋…„ ๋Œ€ํ•œ๋ฏผ๊ตญ ์„ฑ๋ณ„ ์ธ๊ตฌ", 
                                                 subtitle = "์ธ๊ตฌ์ด์กฐ์‚ฌ ์ „์ˆ˜๋ถ€๋ฌธ"))
    .render_notebook()
)

triple_bar
Out[15]:

์ด๋ฒˆ์—๋Š” ๋ฉ‹์žˆ๊ฒŒ ๋ง‰๋Œ€๊ทธ๋ž˜ํ”„์™€ ์„ ๊ทธ๋ž˜ํ”„๋ฅผ ๊ฐ™์ด ๊ทธ๋ ค๋ณด์ž

In [16]:
# data์— ์ƒˆ๋กœ์šด ์ปฌ๋Ÿผ ์ถ”๊ฐ€ - ์„ฑ๋ณ„ ์ฐจ์ด
data["์„ฑ๋ณ„ ์ธ๊ตฌ ์ฐจ์ด"] = data["๋‚จ์ž (๋ช…)"] - data["์—ฌ์ž (๋ช…)"]

man_subtract_woman = list(data["์„ฑ๋ณ„ ์ธ๊ตฌ ์ฐจ์ด"])
In [45]:
bar = (
    Bar()
    .add_xaxis(x)
    .add_yaxis("๋‚จ์ž ์ธ๊ตฌ", man)
    .add_yaxis("์—ฌ์ž ์ธ๊ตฌ", woman)
    .extend_axis(
        yaxis = opts.AxisOpts(
            axislabel_opts = opts.LabelOpts(formatter="{value} ยฐ"), interval=5  # ์ด๊ฑด ๋ชจ๋ฅด๊ฒ ๋‹ค.
        )
    )
    .set_series_opts(label_opts = opts.LabelOpts(is_show = False))   # ๋ง‰๋Œ€๊ทธ๋ž˜ํ”„ ๊ฐ’ ํ‘œ์‹œ off
    .set_global_opts(
        title_opts = opts.TitleOpts(title="๋ง‰๋Œ€๊ทธ๋ž˜ํ”„์— ์„  ๊ทธ๋ž˜ํ”„ ๊ทธ๋ฆฌ๊ธฐ"),
        yaxis_opts = opts.AxisOpts(axislabel_opts = opts.LabelOpts(formatter="{value} ๋ช…")),   # y์ถ• ๊ฐ’์— '๋ช…' ์ถ”๊ฐ€
    )
)

line = Line().add_xaxis(x).add_yaxis("์„ฑ๋ณ„ ์ธ๊ตฌ ์ฐจ์ด", man_subtract_woman, yaxis_index=1)
bar.overlap(line)
bar.render_notebook()
Out[45]:

์œ„์—์„œ ๊ทธ๋ž˜ํ”„ ์คŒ/์•„์›ƒ์„ ์ด๋ฒˆ์—๋Š” ์„ธ๋กœ ๋ฒ„์ „์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

In [46]:
bar = (
    Bar()
    .add_xaxis(x)
    .add_yaxis("๋‚จ์ž ์ธ๊ตฌ", man)
    .add_yaxis("์—ฌ์ž ์ธ๊ตฌ", woman)
    .extend_axis(
        yaxis = opts.AxisOpts(
            axislabel_opts = opts.LabelOpts(formatter="{value} ยฐ"), interval=5  # ์ด๊ฑด ๋ชจ๋ฅด๊ฒ ๋‹ค.
        )
    )
    .set_series_opts(label_opts = opts.LabelOpts(is_show = False))   # ๋ง‰๋Œ€๊ทธ๋ž˜ํ”„ ๊ฐ’ ํ‘œ์‹œ off
    .set_global_opts(
        title_opts = opts.TitleOpts(title="๋ง‰๋Œ€๊ทธ๋ž˜ํ”„์— ์„  ๊ทธ๋ž˜ํ”„ ๊ทธ๋ฆฌ๊ธฐ"),
        yaxis_opts = opts.AxisOpts(axislabel_opts = opts.LabelOpts(formatter="{value} ๋ช…")),   # y์ถ• ๊ฐ’์— '๋ช…' ์ถ”๊ฐ€
        datazoom_opts=opts.DataZoomOpts(orient="vertical")   # ์„ธ๋กœ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์คŒ/์•„์›ƒ ํ•  ์ˆ˜ ์žˆ๋‹ค.
    )
)

line = Line().add_xaxis(x).add_yaxis("์„ฑ๋ณ„ ์ธ๊ตฌ ์ฐจ์ด", man_subtract_woman, yaxis_index=1)
bar.overlap(line)
bar.render_notebook()
Out[46]:

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

In [52]:
bar = (
    Bar()
    .add_xaxis(x)
    .add_yaxis("๋‚จ์ž ์ธ๊ตฌ", man)
    .add_yaxis("์—ฌ์ž ์ธ๊ตฌ", woman)
    .extend_axis(
        yaxis = opts.AxisOpts(
            axislabel_opts = opts.LabelOpts(formatter="{value} ยฐ"), interval=5  # ์ด๊ฑด ๋ชจ๋ฅด๊ฒ ๋‹ค.
        )
    )
    .set_series_opts(label_opts = opts.LabelOpts(is_show = False),
                    markline_opts=opts.MarkLineOpts(data=[opts.MarkLineItem(y=12500000, name="yAxis=๋Œ€๋žต ์ ˆ๋ฐ˜")]))   # ๊ธฐ์ค€์„  ์ถ”๊ฐ€
    .set_global_opts(
        title_opts = opts.TitleOpts(title="๋ง‰๋Œ€๊ทธ๋ž˜ํ”„์— ์„  ๊ทธ๋ž˜ํ”„ ๊ทธ๋ฆฌ๊ธฐ"),
        yaxis_opts = opts.AxisOpts(axislabel_opts = opts.LabelOpts(formatter="{value} ๋ช…")),   # y์ถ• ๊ฐ’์— '๋ช…' ์ถ”๊ฐ€
    )
)

line = Line().add_xaxis(x).add_yaxis("์„ฑ๋ณ„ ์ธ๊ตฌ ์ฐจ์ด", man_subtract_woman, yaxis_index=1)
bar.overlap(line)
bar.render_notebook()
Out[52]:

์ด๊ฑด ๋‚˜๋„ ์ž˜ ๋ชจ๋ฅด๊ฒ ๋‹ค.

In [30]:
from pyecharts.commons.utils import JsCode

cool_bar = (
    Bar()
    .add_xaxis(x)
    .add_yaxis("์ด์ธ๊ตฌ", y, category_gap="20%", label_opts = False) # category_gap์€ ๋ง‰๋Œ€์˜ ๋‘๊ป˜๋กœ ๋†’์„์ˆ˜๋ก ์–‡์•„์ง„๋‹ค.
    .set_series_opts(
        itemstyle_opts={
            "normal": {
                "color": JsCode(
                    """new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                offset: 0,
                color: 'rgba(0, 244, 255, 1)'
            }, {
                offset: 1,
                color: 'rgba(0, 77, 167, 1)'
            }], false)"""
                ),
                "barBorderRadius": [10, 10, 0, 0],      # ๋ง‰๋Œ€๊ทธ๋ž˜ํ”„์˜ ๋‘ฅ๊ทผ ์ •๋„ ์„ค์ •
                "shadowColor": "rgb(0, 160, 221)",
            }
        }
    )
    .set_global_opts(title_opts=opts.TitleOpts(title="2020๋…„ ๋Œ€ํ•œ๋ฏผ๊ตญ ์ด์ธ๊ตฌ"))
    .render_notebook()
)

cool_bar
Out[30]:
In [ ]: