1. Seabron Library ?

 

๐Ÿ‹  ์‹œ๋ณธ Seaborn ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๋งทํ”Œ๋กœ๋ฆฝ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ๋‹ค์–‘ํ•œ ํ…Œ๋งˆ์™€ ํ†ต๊ณ„์šฉ ์ฐจํŠธ ๋“ฑ์˜ ๋™์ ์ธ ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
๐Ÿ‹  ์‹œ๋ณธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๋งทํ”Œ๋กœ๋ฆฝ๊ณผ ๋‹ค๋ฅด๊ฒŒ ํ†ต๊ณ„์™€ ๊ด€๋ จ๋œ ์ฐจํŠธ๋ฅผ ์ œ๊ณตํ•˜๊ธฐ ๋–„๋ฌธ์— ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„์œผ๋กœ ๋‹ค์–‘ํ•œ ํ†ต๊ณ„ ์ง€ํ‘œ๋ฅผ ๋งŒ๋“ค์–ด ๋‚ผ ์ˆ˜ ์žˆ์œผ๋ฉฐ ๋ฐ์ดํ„ฐ ๋ถ„์„์— ํ™œ๋ฐœํ•˜๊ฒŒ ์‚ฌ์šฉ๋˜๊ณ  ์žˆ๋‹ค

๐Ÿ‹  ์‹œ๋ณธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๊ทธ๋ฆฌ๋Š” ๊ทธ๋ž˜ํ”„๋“ค์€ ํฌ๊ฒŒ ๊ด€๊ณ„ํ˜•, ๋ถ„ํฌํ˜•, ์นดํ…Œ๊ณ ๋ฆฌํ˜•์˜ ์„ธ๊ฐ€์ง€ ๋ฒ”์ฃผ๋กœ ๋ถ„๋ฅ˜
       โ–ถ๏ธ  ์‹ค์ œ ๋ถ„์„์—๋Š” ๋งทํ”Œ๋กœ๋ฆฝ๊ณผ ์‹œ๋ณธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋‘ ๊ฐ€์ง€๋ฅผ ํ•จ๊ป˜ ์‚ฌ์šฉ
๐Ÿ‹  ์‚ฌ์šฉํ•  ๋•Œ ์ฃผ์˜ํ•  ์ ์€ ์‹œ๋ณธ์ด ๋งทํ”Œ๋กœ๋ฆฝ์— ์˜์กด์ ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋งทํ”Œ๋กœ๋ฆฝ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋„ ๋ฐ˜๋“œ์‹œ ํ•จ๊ป˜ ์ž„ํฌํŠธ ํ•ด์•ผ ํ•จ

๐Ÿ’ก ์‹œ๋ณธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์ฃผ์š” ํŠน์ง• ๐Ÿ’ก
     a. ๋›ฐ์–ด๋‚œ ์‹œ๊ฐํ™” ํšจ๊ณผ 

     b. ๊ฐ„๊ฒฐํ•œ ๊ตฌ๋ฌธ ์ œ๊ณต 

     c. ํŒ๋‹ค์Šค ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„์— ์ตœ์ ํ™” 

     d. ์‰ฌ์šด ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„ ์ง‘๊ณ„ ๋ฐ ์ฐจํŠธ ์š”์•ฝ

๐Ÿ‹  ๊ธฐ๋ณธ์ ์œผ๋กœ ๋งทํ”Œ๋กœ๋ฆฝ๋ณด๋‹ค ์ œ๊ณตํ•˜๋Š” ์ƒ‰์ƒ์ด ๋” ๋งŽ๊ธฐ์— ์ƒ‰ ํ‘œํ˜„๋ ฅ์ด ์ข‹์Œ
๐Ÿ‹  ๋งทํ”Œ๋กœ๋ฆฝ์œผ๋กœ ๊ทธ๋ž˜ํ”„๋ฅผ ํ‘œํ˜„ํ•˜๋”๋ผ๋„ ์‹œ๋ณธ์˜ set() ํ•จ์ˆ˜๋ฅผ ๋ฏธ๋ฆฌ ์„ ์–ธํ•ด ์ฃผ๋ฉด ์ž๋™์œผ๋กœ ์‹œ๋ณธ ํŒ”๋ ˆํŠธ์— ์ถœ๋ ฅ
๐Ÿ‹  ์‹œ๋ณธ์€ 'deep, muted, pastel, bright, dark, colorblind'์˜ 6๊ฐœ ๊ธฐ๋ณธ ํŒ”๋ ˆํŠธ๋ฅผ ์ œ๊ณต

https://seaborn.pydata.org/

 

seaborn: statistical data visualization — seaborn 0.13.2 documentation

seaborn: statistical data visualization

seaborn.pydata.org


 

2. ๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™” ์ค€๋น„ํ•˜๊ธฐ


 1) ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ฐ ๋ฐ์ดํ„ฐ ์ฝ์–ด์˜ค๊ธฐ 

# 2020๋…„ ๊ฑด๊ฐ•๊ฒ€์ง„ ์ผ๋ถ€ ๋ฐ์ดํ„ฐ ์—‘์…€ ํŒŒ์ผ์„ ์ฝ์–ด์™€ ๋™์ ์ธ ์‹œ๊ฐํ™”๋ฅผ ํ‘œํ˜„
import pandas as pd

data = pd.read_excel('../input/health_screenings_2020_1000ea.xlsx')
data.head()

์ถœ๋ ฅ ๊ฒฐ๊ณผ

 


 

2) ๋ฐ์ดํ„ฐ ์ „์ฒ˜๋ฆฌ

# ์„ฑ๋ณ„, ์Œ์ฃผ ์—ฌ๋ถ€, ํก์—ฐ ์ƒํƒœ์— ๋Œ€ํ•˜์—ฌ ์ˆซ์ž๋กœ ์ €์žฅ๋˜์–ด ์žˆ๋Š” ์ •๋ณด๋ฅผ ๋ฐ์ดํ„ฐ ๋ถ„์„์˜ ๊ฐ€๋…์„ฑ์„ ๋†’์ด๊ธฐ ์œ„ํ•ด
# 'Male', 'Female', 'Non-drinking', 'Drinking', 'Non-smoking', 'Smoking'์˜ ๋ฌธ์ž์—ด๋กœ 
# ๋ณ€๊ฒฝํ•˜์—ฌ ๋ฐ์ดํ„ฐ ์ „์ฒ˜๋ฆฌ

# ํ•„์š” ์ปฌ๋Ÿผ ์ถ”์ถœํ•˜์—ฌ ์ €์žฅ
data6 = data[['gender', 'height', 'weight', 'waist', 'drinking', 'smoking']]
data6.head()
# ์„ฑ๋ณ„ ๋ฐ์ดํ„ฐ๋ฅผ Male๊ณผ Female๋กœ ๋ณ€๊ฒฝ
data6.loc[data6['gender'] == 1, ['gender']] = 'Male'
data6.loc[data6['gender'] == 2, ['gender']] ='Female'

# ์Œ์ฃผ ์—ฌ๋ถ€ 0(๋น„์Œ์ฃผ)๋Š” Non-drinking, 1(์Œ์ฃผ)๋Š” Drinking์œผ๋กœ ๋ณ€๊ฒฝ
data6.loc[data6['drinking'] == 0, ['drinking']] = 'Non-drinking'
data6.loc[data6['drinking'] == 1, ['drinking']] = 'Drinking'

# ํก์—ฐ์ƒํƒœ 1(๋น„ํก์—ฐ)๊ณผ 2(ํก์—ฐ ๋Š์Œ)์„ Non-smoking์œผ๋กœ ๋ณ€๊ฒฝํ•˜๊ณ , 3(ํก์—ฐ)์„ Smoking์œผ๋กœ ๋ณ€๊ฒฝ
data6.loc[(data6['smoking'] ==1) | (data6['smoking'] ==2), ['smoking']] = 'Non-smoking'
data6.loc[data6['smoking'] == 3, ['smoking']] = 'Smoking'

data6.head()

 

์ถœ๋ ฅ ๊ฒฐ๊ณผ

 

# ๋ฐ์ดํ„ฐ ํƒ€์ž… ๋ณ€๊ฒฝ์—†์ด ์ €์žฅ
data6.to_pickle('../output/data6.pickle')

 

3.  sns.barplot()

๐Ÿ‹  ์‹œ๋ณธ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„๋Š” barplot() ํ•จ์ˆ˜๋กœ ์†์„ฑ 3๊ฐœ๋ฅผ ์ง€์ •ํ•˜์—ฌ ๋ฒ”์ฃผ๋ณ„ ๊ทธ๋ฃน์„ ์‰ฝ๊ฒŒ ํ‘œํ˜„
๐Ÿ‹  ์‹œ๋ณธ ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ์˜ค์ฐจ ๋ง‰๋Œ€๊ฐ€ ํ‘œ์‹œ ๋˜๋Š”๋ฐ, ์˜ค์ฐจ ๋ง‰๋Œ€๋ฅผ ๊ทธ๋ฆฌ๋Š” ๋ฒ”์œ„๋ฅผ ์‹ ๋ขฐ๊ตฌ๊ฐ„์ด๋ผ๊ณ  ํ•จ
        โ–ถ๏ธ ์˜ค์ฐจ ๋ง‰๋Œ€ ์‹ ๋ขฐ๊ตฌ๊ฐ„์„ ํ‘œ์ค€ํŽธ์ฐจ๋กœ ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ci ์†์„ฑ์„ 'sd'(ci='sd')๋กœ ์ง€์ •

# ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ธ์ˆ˜๋ฅผ ๊ฐ€์ง„๋‹ค
sns.barplot(x=None, y=None, hue=None, data=None, order=None, 
            hue_order=None, estimator=<function mean at 0x7f9e05dcf5e0>, 
            ci=95, n_boot=1000, units=None, seed=None, orient=None, 
            color=None, palette=None, saturation=0.75, errcolor='.26', 
            errwidth=None, capsize=None, dodge=True, ax=None, **kwargs)

 

<x>  x์ถ•์— ์‚ฌ์šฉํ•  ๋ฐ์ดํ„ฐ์˜ ์—ด ์ด๋ฆ„ ๋˜๋Š” ์œ„์น˜ (์ •์ˆ˜) <y> y์ถ•์— ์‚ฌ์šฉํ•  ๋ฐ์ดํ„ฐ์˜ ์—ด ์ด๋ฆ„ ๋˜๋Š” ์œ„์น˜ (์ •์ˆ˜)
<hue> ๋ฒ”๋ก€์— ์‚ฌ์šฉํ•  ๋ฐ์ดํ„ฐ์˜ ์—ด ์ด๋ฆ„ ๋˜๋Š” ์œ„์น˜ (์ •์ˆ˜) <data> ๊ทธ๋ž˜ํ”„๋ฅผ ๊ทธ๋ฆด ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„
<order> ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„๋ฅผ ๊ทธ๋ฆด ๋•Œ, x์ถ• ๊ฐ’๋“ค์˜ ์ˆœ์„œ <hue_order> ๋ฒ”๋ก€์— ํ‘œ์‹œ๋  ๊ฐ’๋“ค์˜ ์ˆœ์„œ
<estimator> ๋ง‰๋Œ€์˜ ๋†’์ด๋ฅผ ์–ด๋–ป๊ฒŒ ๊ณ„์‚ฐํ•  ๊ฒƒ์ธ์ง€๋ฅผ ์ง€์ •ํ•˜๋Š” ํ•จ์ˆ˜
                          (๊ธฐ๋ณธ๊ฐ’: mean)
<ci> ์‹ ๋ขฐ ๊ตฌ๊ฐ„์„ ์„ค์ •ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๊ฐ’ (๊ธฐ๋ณธ๊ฐ’: 95)
<n_boot> ์‹ ๋ขฐ ๊ตฌ๊ฐ„ ๊ณ„์‚ฐ์— ์‚ฌ์šฉํ•  ๋ถ€ํŠธ์ŠคํŠธ๋žฉ ์ƒ˜ํ”Œ๋ง ์ˆ˜
                     (๊ธฐ๋ณธ๊ฐ’: 1000)
<units> ๊ทธ๋ž˜ํ”„๋ฅผ ๊ทธ๋ฆด ๋•Œ ์‚ฌ์šฉํ•  ๋ฐ์ดํ„ฐ์˜ ๋‹จ์œ„
<seed> ๋‚œ์ˆ˜ ๋ฐœ์ƒ ์‹œ๋“œ ๊ฐ’ <orient> ๊ทธ๋ž˜ํ”„์˜ ๋ฐฉํ–ฅ ('v' ๋˜๋Š” 'h', ๊ธฐ๋ณธ๊ฐ’: 'v')
<color> ๋ชจ๋“  ๋ง‰๋Œ€์˜ ์ƒ‰์ƒ์„ ์ง€์ •ํ•˜๋Š” ๋‹จ์ผ ๊ฐ’ ๋˜๋Š” ์ƒ‰์ƒ ๋งต <palette> ๋ฒ”์ฃผํ˜• ๋ณ€์ˆ˜์— ๋Œ€ํ•œ ์ƒ‰์ƒ ๋งต
<saturation> ์ƒ‰์ƒ ๋งต์˜ ์ฑ„๋„ <errcolor> ์˜ค์ฐจ ๋ง‰๋Œ€์˜ ์ƒ‰์ƒ
<errwidth> ์˜ค์ฐจ ๋ง‰๋Œ€์˜ ๋‘๊ป˜ <capsize> ์˜ค์ฐจ ๋ง‰๋Œ€ ๋ ๋ถ€๋ถ„์˜ ํฌ๊ธฐ
<dodge> ๋ง‰๋Œ€๋ฅผ ์„œ๋กœ ๊ตฌ๋ถ„ํ•˜๊ธฐ ์œ„ํ•œ ์—ฌ์œ  ๊ณต๊ฐ„ ์—ฌ๋ถ€ (๊ธฐ๋ณธ๊ฐ’: True) <ax> ๊ทธ๋ž˜ํ”„๋ฅผ ๊ทธ๋ฆด matplotlib์˜ ์ถ• ๊ฐ์ฒด

 

1) barplot() ํ•จ์ˆ˜ ์‚ฌ์šฉ ์˜ˆ์‹œ

# ๋ชจ๋“ˆ import
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

# ๋ฐ์ดํ„ฐ ํ”„๋ ˆ์ž„ ์ƒ์„ฑ
data6 = pd.read_pickle('../output/data6.pickle')

# ์Œ์ฃผ ์—ฌ๋ถ€ ๋ฐ ํก์—ฐ ์ƒํƒœ ๋ฐ์ดํ„ฐ ์ค€๋น„ํ•˜๊ธฐ
# data6์—์„œ ์„ฑ๋ณ„, ์Œ์ฃผ ์—ฌ๋ถ€์˜ ๊ทธ๋ฃน๋ณ„ ๊ฐœ์ˆ˜(์ธ์›)๋ฅผ ๊ตฌํ•˜์—ฌ drinking์— ์ €์žฅ
drinking = data6.groupby(['gender', 'drinking'])['drinking'].count()

# data6์—์„œ ์„ฑ๋ณ„, ํก์—ฐ ์ƒํƒœ์˜ ๊ทธ๋ฃน๋ณ„ ๊ฐœ์ˆ˜(์ธ์›)๋ฅผ ๊ตฌํ•˜์—ฌ smoking์— ์ €์žฅ
smoking = data6.groupby(['gender', 'smoking'])['smoking'].count()

# ์Œ์ฃผ ์—ฌ๋ถ€์™€ ํก์—ฐ ์ƒํƒœ์— ๋Œ€ํ•œ ๊ทธ๋ฃน๋ณ„ ๊ฐœ์ˆ˜(์ธ์›)์˜ ์‹œ๋ฆฌ์ฆˆ๋ฅผ ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„์œผ๋กœ ๋ณ€๊ฒฝ
drinking = drinking.to_frame(name='count')
smoking = smoking.to_frame(name='count')

 

  ๐Ÿ“Œ  series.to_frame() : series โ–ถ๏ธ dataframe ์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋Š” ํ•จ์ˆ˜

๋ฐ์ดํ„ฐ ํ”„๋ ˆ์ž„ ๋ณ€๊ฒฝ ๊ฒฐ๊ณผ

 

# ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„์˜ ์ธ๋ฑ์Šค๋ฅผ ์ดˆ๊ธฐํ™”
drinking = drinking.reset_index()
smoking = smoking.reset_index()
drinking
# ์ปฌ๋Ÿผ์ด 1๊ฐœ -> 3๊ฐœ๋กœ ๋ณ€๊ฒฝ๋จ

 

  ๐Ÿ“Œ  reset_index() : ์„ค์ • ์ธ๋ฑ์Šค๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  ๊ธฐ๋ณธ ์ธ๋ฑ์Šค(0,1,2, ... , n)์œผ๋กœ ๋ณ€๊ฒฝ

์ธ๋ฑ์Šค ์ดˆ๊ธฐํ™” ๊ฒฐ๊ณผ


# ์„ฑ๋ณ„ ์Œ์ฃผ ์—ฌ๋ถ€ ๋ฐ ํก์—ฐ ์ƒํƒœ ์‹œ๋ณธ ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„
fig = plt.figure(figsize=(17, 6))

# 1ํ–‰ 2์—ด์˜ ์„œ๋ธŒํ”Œ๋กฏ ์ƒ์„ฑ
area1 = fig.add_subplot(1, 2, 1)
area2 = fig.add_subplot(1, 2, 2)

# barplot() ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ x์ถ•์— ์„ฑ๋ณ„, y์ถ•์— ์Œ์ฃผ์—ฌ๋ถ€ ๊ฐœ์ˆ˜ (์ธ์›), hue์— ์„ฑ๋ณ„ ์Œ์ฃผ ์—ฌ๋ถ€๋ฅผ ํ• ๋‹นํ•˜์—ฌ ์ฒซ ๋ฒˆ์งธ ์„œ๋ธŒํ”Œ๋กฏ์— ํ• ๋‹น
ax1 = sns.barplot(data=drinking, x='gender', y='count', hue='drinking', ax=area1)
# barplot() ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ x์ถ•์— ์„ฑ๋ณ„, y์ถ•์— ํก์—ฐ์ƒํƒœ ๊ฐœ์ˆ˜ (์ธ์›), hue์— ์„ฑ๋ณ„ ํก์—ฐ์ƒํƒœ ๊ทธ๋ฃน๋ณ„ ๋ฐ์ดํ„ฐ๋ฅผ ํ• ๋‹นํ•˜์—ฌ
# ๋‘ ๋ฒˆ์งธ ์„œ๋ธŒํ”Œ๋กฏ์— ํ• ๋‹น
ax2 = sns.barplot(data=smoking, x='gender', y='count', hue='smoking', ax=area2)

fig.suptitle('2020 Health Screenings Drinking & Smoking Type Seaborn Bar Graph', fontweight='bold')
area1.set_title('Drinking Type')
area2.set_title('Smoking Type')

plt.show()

์ถœ๋ ฅ ๊ฒฐ๊ณผ

 


 

4.  add_subplot() ํ•จ์ˆ˜

๐Ÿ‹  add_subplot() ํ•จ์ˆ˜์˜ ์ธ์ž๋ฅผ ํ†ตํ•ด ์„œ๋ธŒํ”Œ๋กฏ ๊ฐœ์ˆ˜๋ฅผ ์กฐ์ •
      ๐Ÿ“ add_subplot(1, 2, 1)์€ 1 X 2 (ํ–‰ X ์—ด)์˜ ์„œ๋ธŒํ”Œ๋กฏ์„ ์ƒ์„ฑํ•œ๋‹ค๋Š” ์˜๋ฏธ
             โžก๏ธ  ์„ธ ๋ฒˆ์งธ ์ธ์ž 1์€ ์ƒ์„ฑ๋œ ๋‘ ๊ฐœ์˜ ์„œ๋ธŒํ”Œ๋กฏ ์ค‘ ์ฒซ ๋ฒˆ์งธ ์„œ๋ธŒํ”Œ๋กฏ์„ ์˜๋ฏธ
      ๐Ÿ“ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ (1, 2, 2)๋Š” 1 X 2 ์„œ๋ธŒํ”Œ๋กฏ์—์„œ ๋‘ ๋ฒˆ์งธ ์„œ๋ธŒํ”Œ๋กฏ์„ ์˜๋ฏธ

 

# ์„ฑ๋ณ„ ์Œ์ฃผ ์—ฌ๋ถ€ ๋ฐ ํก์—ฐ ์ƒํƒœ ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„

# 1) ์ „์ฒด ์„ค์ •
fig = plt.figure(figsize=(17,6))  # ๊ทธ๋ž˜ํ”„ ํฌ๊ธฐ ์ง€์ • ๋ฐ ๊ทธ๋ฆผ ๊ฐ์ฒด ์ƒ์„ฑ
fig.suptitle('2020 Health Screenings Drinking & Smoking Type Bar Graph', fontweight='bold')
index = np.arange(4)  # x์ถ• ๋ˆˆ๊ธˆ ๊ฐœ์ˆ˜๋ฅผ ๋ฐฐ์—ด๋กœ ์ƒ์„ฑํ•˜๊ณ  index์— ์ €์žฅ

# 2) ์ฒซ ๋ฒˆ์จฐ ์„œ๋ธŒํ”Œ๋กฏ ์„ค์ •
fig.add_subplot(1, 2, 1)  # 1ํ–‰ 2์—ด์˜ ์„œ๋ธŒํ”Œ๋กฏ ์ค‘ ์ฒซ ๋ฒˆ์จฐ ์„œ๋ธŒํ”Œ๋กฏ์„ ์ƒ์„ฑ
# ์ฒซ ๋ฒˆ์งธ ์„œ๋ธŒํ”Œ๋กฏ์— ๊ทธ๋ ค์งˆ ์Œ์ฃผ ์—ฌ๋ถ€ ๋ฐ์ดํ„ฐ ๊ฐœ์ˆ˜ (์ธ์›)์„ bar() ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ ์ €์žฅ.
plt.bar(index, drinking['count'])
plt.title('Drinking Type')
plt.ylabel('Count')
# x์ถ• ๋ˆˆ๊ธˆ ์ด๋ฆ„ ์ง€์ •
plt.xticks(index, ['Drinking(Female)', 'Non-drinking(Female)', 'Drinking(Male)', 'Non-drinking(Male)'])

# 3) ๋‘ ๋ฒˆ์งธ ์„œ๋ธŒํ”Œ๋กฏ ์„ค์ •
fig.add_subplot(1, 2, 2)  # 1ํ–‰ 2์—ด์˜ ์„œ๋ธŒํ”Œ๋กฏ ์ค‘ ๋‘ ๋ฒˆ์จฐ ์„œ๋ธŒํ”Œ๋กฏ์„ ์ƒ์„ฑ
# ๋‘ ๋ฒˆ์งธ ์„œ๋ธŒํ”Œ๋กฏ์— ๊ทธ๋ ค์งˆ ํก์—ฐ ์ƒํƒœ ๋ฐ์ดํ„ฐ ๊ฐœ์ˆ˜ (์ธ์›)์„ bar()ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ ์ €์žฅ
plt.bar(index, smoking['count'])
plt.title('Smoking Type')
plt.ylabel('Count')
# x์ถ• ๋ˆˆ๊ธˆ ์ด๋ฆ„ ์ง€์ •
plt.xticks(index, ['Non-smoking(Female)', 'Smoking(Female)', 'Non-smoking(Male)', 'Smoking(Male)'])

 

์ถœ๋ ฅ ๊ฒฐ๊ณผ

 

 

 

 

 

 

[ ๋‚ด์šฉ ์ฐธ๊ณ  : IT ํ•™์› ๊ฐ•์˜ ๋ฐ ์œ„ํ‚ค๋…์Šค ]

+ Recent posts