๐ํ์ด์ฌ ๋จธ์ ๋ฌ๋ ํ๋ค์ค ๋ฐ์ดํฐ๋ถ์ 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()
๋ฐ์ค ํ๋กฏ์ ๋ฒ์ฃผํ ๋ฐ์ดํฐ ๋ถํฌ์ ์ฃผ์ ํต๊ณ ์งํ๋ฅผ ํจ๊ป ์ ๊ณตํจ
๋ค๋ง, ๋ฐ์ค ํ๋กฏ๋ง์ผ๋ก๋ ๋ฐ์ดํฐ๊ฐ ํผ์ ธ์๋ ๋ถ์ฐ์ ์ ๋๋ฅผ ์ ํํ๊ฒ ์๊ธฐ๋ ์ด๋ ต๊ธฐ ๋๋ฌธ์, ์ปค๋ ๋ฐ๋ ํจ์ ๊ทธ๋ํ๋ฅผ 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)