티스토리 뷰

countplot

  • 카테고리별 데이터 값을 셀 수 있음
  • 별도의 집계 코드를 작성하지 않아도 됨
    • matplotlib 에서 카운팅 그래프를 그리기 위해선, 카테고리별 집계 코드가 필요함

 

import seaborn as sns
titanic = sns.load_dataset('titanic')
sns.countplot(x="class", data=titanic)
plt.show()

 

 

 

 

 

 

 

distplot

  • 히스토그램 그릴 때 사용
  • 러그나 커널 밀도와 같이 추정된 확률밀도함수 표시 기능이 있음
  • hist_kws : 그래프를 꾸밀 수 있음
    • edgecolor : 바그래프 테두리 색상 
    • facecolor : 바그래프 내부 색상
    • linewidth : 바그래프 테두리 굵기

x = np.random.randn(200)
sns.distplot(x, kde=True, hist_kws={"facecolor":"red", "edgecolor":"black", "linewidth":2})

 

 

 

 

 

 

 

 

 

heatmap

  • 데이터의 상관관계나 pivot 테이블을 시각화하고 싶을 때 사용
  • 데이터 상관관계 구하는 함수 사용 corr()
  • 옵션
    • annot : 셀 안에 값 표시 여부

 

plt.figure(figsize=(10,6))
sns.heatmap(titanic.corr(), annot=True, cmap='RdYlGn')

 

 

 

 

 

 

 

 

catplot

  • categorical plot 
  • 카테고리형 변수를 시각화할 때 사용
  • 옵션
    • col : 지정한 컬럼의 값에 따라 다중 그래프 생성
    • kind : 차트 종류
      • bar : 자동으로 값의 범위가 계산되어 그래프가 그려짐
      • strip : 기본값
      • swarm
      • box
      • violin
      • boxen
      • point
      • bar
      • count

 

sns.set(style='darkgrid')
sns.catplot(x="who", y="survived", data=titanic).set(title="kind = strip")

 

 

 

 

 

 

 

 

 

 

sns.catplot(x="who", y="survived", data=titanic, kind="bar").set(title="kind = bar")

 

 

 

 

 

 

 

 

 

 

sns.catplot(x="who", y="survived", col="class", data=titanic, kind="violin")

댓글