티스토리 뷰

replot

  • relation plot
  • 라인 그래프와 산점도 그래프를 모두 그릴 수 있는 방법
  • 옵션
    • hue : 지정된 컬럼값에 따라 그래프 색상이 구분됨 
    • col : 지정된 컬럼값에 따라 다중 그래프가 자동으로 생성됨
    • ci : 신뢰구간 설정값
      • N%의 신뢰구간
      • 선그래프일 때에만 유효함 (when kind='line')
      • 선그래프를 따라 반투명의 신뢰구간이 생김
      • 설정 안하려면 None/False/0
    • kind : 그래프 스타일
      • line : 선 그래프
      • scatter : 산점도 그래프 (기본값)
    • palette : 색상 조합 

선그래프 그리기

 

import seaborn as sns

sns.set(style='darkgrid')
plt.rc('font', size=15)
fmri = sns.load_dataset("fmri")

sns.relplot(x='timepoint', y='signal', kind='line', data=fmri, ci=50)

 

 

 

다중 선그래프 그리기

- col='time' : 컬럼 'time'의 값 (dinner, lunch) 각각에 대한 그래프가 생성됨

- hue='day' : 컬럼 'day'의 값에 따라 색상이 구분됨 (thur, fri, sat, sun)

 

sns.relplot(x='total_bill', y='tip', hue='day', col='time', kind='line', data=tips, palette='magma')

 

 

산점도 그래프 그리기

 

sns.relplot(x='total_bill', y='tip', hue='smoker', data=tips, palette='Reds')

 

 

 

 

 

 

 

 

산점도 다중 그래프 그리기 (col)

- col=time 으로 옵션을 설정하였으니, time 값 (dinner, lunch) 각각에 대한 그래프가 생성됨

- hue='day' : 컬럼 'day'의 값에 따라 색상이 구분됨 (thur, fri, sat, sun)

sns.relplot(x='total_bill', y='tip', hue='day', col='time', data=tips, palette='magma')

댓글