SiLaure's Data

[Seaborn] 02. histplot & displot 본문

Records of/Learning

[Seaborn] 02. histplot & displot

data_soin 2021. 7. 26. 10:21

- Seaborn을 사용하기 전에 ...

 

  • Library와 data를 불러오고, 시각화를 위한 세팅 하기
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt


import seaborn as sns
sns.set_theme(style='whitegrid')

penguins = sns.load_dataset('penguins')
penguins

출력 : 

seaborn에서 기본 제공하는 penguin data

 

 

 

- 기본 구문 구성

 sns.~~~plot(data = xxx, x, y, hue)
hue : 색상을 나누는 기준

 

 

- Histplot

  • 가장 기본적으로 사용되는 히스토그램을 출력하는 plot.
  • 전체 데이터를 특정 구간별 정보를 확인할 때 사용한다.

 

  • e.g.
sns.histplot(data=penguins, x='flipper_length_mm', hue='species')

출력 :

색이 겹쳐서 보기 힘들다.

  • 색을 겹치지 않고 전체적으로(histogram 별로) 보는 경우
sns.histplot(data=penguins, x='flipper_length_mm', hue='species', multiple='stack')

출력 :

 

 

 

 

 

- Displot

  • distribution들을 여러 subplot들(figure들)로 나눠서 출력해주는 plot
  • 정보를 따로따로 출력하고 싶을 때
  • displot에 kind를 변경하는 것으로, histplot, kdeplot, ecdfplot 모두 출력이 가능하다.
e.g. displot(kind="hist")
sns.displot(data=penguins, x='flipper_length_mm', hue='species', col='species')

출력 :

 

 

 

 

Comments