๐Ÿ“šํŒŒ์ด์ฌ ๋จธ์‹ ๋Ÿฌ๋‹ ํŒ๋‹ค์Šค ๋ฐ์ดํ„ฐ๋ถ„์„ part4. ๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™”

๐Ÿ“„part4 seaborn.ipynb

๐Ÿฟ๏ธ๋นˆ๋„ ๊ทธ๋ž˜ํ”„

๊ฐ ๋ฒ”์ฃผ์— ์†Œํ•˜๋Š” ๋ฐ์ดํ„ฐ์˜ ๊ฐœ์ˆ˜๋ฅผ ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„๋กœ ๋‚˜ํƒ€๋‚ด๋Š” countplot() ํ•จ์ˆ˜ ๊ทธ๋ž˜ํ”„ ์ƒ‰ ๊ตฌ์„ฑ์„ ๋‹ค๋ฅด๊ฒŒ ํ•˜๋ ค๋ฉด palette ์˜ต์…˜์„ ๋ณ€๊ฒฝํ•˜์—ฌ ์ ์šฉํ•จ

# ๊ทธ๋ž˜ํ”„ ๊ฐ์ฒด ์ƒ์„ฑ
fig=plt.figure(figsize=(15,5))
ax1=fig.add_subplot(1,3,1)
ax2=fig.add_subplot(1,3,2)
ax3=fig.add_subplot(1,3,3)

# ๊ธฐ๋ณธ๊ฐ’
sns.countplot(x='class', palette='Set1', data=titanic, ax=ax1)

# hue์˜ต์…˜์— 'who' ์ถ”๊ฐ€
sns.countplot(x='class', hue='who', palette='Set2', data=titanic, ax=ax2)

# dodge=False ์˜ต์…˜ ์ถ”๊ฐ€ (์ถ• ๋ฐฉํ–ฅ์œผ๋กœ ๋ถ„๋ฆฌํ•˜์ง€ ์•Š๊ณ  ๋ˆ„์  ๊ทธ๋ž˜ํ”„ ์ถœ๋ ฅ)
sns.countplot(x='class', hue='who', palette='Set3', dodge=False, data=titanic, ax=ax3)

# ์ฐจํŠธ ์ œ๋ชฉ ํ‘œ์‹œ
ax1.set_title('titanic class')
ax2.set_title('titanic class - who')
ax3.set_title('titanic class - who(stacked)')

plt.show()

Untitled

๐Ÿฟ๏ธ ๋ฐ•์Šค ํ”Œ๋กฏ/ ๋ฐ”์ด์˜ฌ๋ฆฐ ๊ทธ๋ž˜ํ”„

๋ฐ•์Šค ํ”Œ๋กฏ์€ ๋ฒ”์ฃผํ˜• ๋ฐ์ดํ„ฐ ๋ถ„ํฌ์™€ ์ฃผ์š” ํ†ต๊ณ„ ์ง€ํ‘œ๋ฅผ ํ•จ๊ป˜ ์ œ๊ณตํ•จ

๋‹ค๋งŒ, ๋ฐ•์Šค ํ”Œ๋กฏ๋งŒ์œผ๋กœ๋Š” ๋ฐ์ดํ„ฐ๊ฐ€ ํผ์ ธ์žˆ๋Š” ๋ถ„์‚ฐ์˜ ์ •๋„๋ฅผ ์ •ํ™•ํ•˜๊ฒŒ ์•Œ๊ธฐ๋Š” ์–ด๋ ต๊ธฐ ๋•Œ๋ฌธ์—, ์ปค๋„ ๋ฐ€๋„ ํ•จ์ˆ˜ ๊ทธ๋ž˜ํ”„๋ฅผ y์ถ• ๋ฐฉํ–ฅ์— ์ถ”๊ฐ€ํ•˜์—ฌ ๋ฐ”์ด์˜ฌ๋ฆฐ ๊ทธ๋ž˜ํ”„๋ฅผ ๊ทธ๋ฆฌ๋Š” ๊ฒฝ์šฐ๋„ ์žˆ์Œ

๋ฐ•์Šคํ”Œ๋กฏ์€ boxplot()ํ•จ์ˆ˜๋กœ ๊ทธ๋ฆฌ๊ณ , ๋ฐ”์ด์˜ฌ๋ฆฐ ๊ทธ๋ž˜ํ”„๋Š” violinplot()ํ•จ์ˆ˜๋กœ ๊ทธ๋ฆผ

# ๊ทธ๋ž˜ํ”„ ๊ฐ์ฒด ์ƒ์„ฑ
fig=plt.figure(figsize=(15,10))
ax1=fig.add_subplot(2,2,1)
ax2=fig.add_subplot(2,2,2)
ax3=fig.add_subplot(2,2,3)
ax4=fig.add_subplot(2,2,4)

# ๋ฐ•์Šคํ”Œ๋กฏ - ๊ธฐ๋ณธ๊ฐ’
sns.boxplot(x='alive', y='age', data=titanic, ax=ax1)

# ๋ฐ•์Šคํ”Œ๋กฏ - hue๋ณ€์ˆ˜ ์ถ”๊ฐ€
sns.boxplot(x='alive', y='age', hue='sex', data=titanic, ax=ax2)

# ๋ฐ”์ด์˜ฌ๋ฆฐํ”Œ๋กฏ - ๊ธฐ๋ณธ๊ฐ’
sns.violinplot(x='alive', y='age', data=titanic, ax=ax3)

# ๋ฐ”์ด์˜ฌ๋ฆฐํ”Œ๋กฏ - hue๋ณ€์ˆ˜ ์ถ”๊ฐ€
sns.violinplot(x='alive', y='age', hue='sex', data=titanic, ax=ax4)

Untitled