728x90
- 모듈 불러오기
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
- seaborn안에 tips데이터 불러오기
# tips 데이터 불러오기
tips = sns.load_dataset('tips')
# 데이터 확인
tips.head()
- relplot
- scatter plot
# x : x축 column
# y : y축 column
# data : 사용할 data frame
sns.relplot(x="total_bill", y="tip", data=tips)
# hue(명목형) : 해당 변수를 기준으로 색깔 다르게 표시
sns.relplot(x="total_bill", y="tip", hue='sex', data=tips)
# hue(실수형) : 해당 변수를 기준으로 색깔 그라데이션으로 표시
sns.relplot(x="total_bill", y="tip", hue='size', data=tips)
# style: 해당 point의 marker를 다르게 표시
sns.relplot(x="total_bill", y="tip", hue='sex', style='smoker', data=tips)
# size: 점의 크기 조정
sns.relplot(x="total_bill", y="tip", hue='sex', style='smoker', size='size', data=tips)
# alpha: 점의 투명도 조정(0~1)
sns.relplot(x="total_bill", y="tip", hue='sex', style='smoker', size='size', alpha=0.3, data=tips)
# col : 선택된 변수에 따라서 subplot을 그려준다
sns.relplot(x="total_bill", y="tip", hue='sex', col='smoker', data=tips)
- line plot
# x : x축 column
# y : y축 column
# data : 사용할 data frame
# hue : 집단별 구분
# style : 해당 point의 marker를 다르게 표시
sns.relplot(x="tip", y="total_bill", hue='sex', style='sex', data=tips, kind='line')
- catplot(변수가 명목형일때 사용)
- strip plot
# kind : 'strip'
# order : 명목형 범주 지정
# jitter : 점이 겹쳐있을 때 살짝 떨어져서 보이게 만드는 기능
sns.catplot(x="smoker", y="tip", kind='strip', order=["No", "Yes"], jitter=False, data=tips)
- box plot
# kind : 'box'
sns.catplot(x="smoker", y="tip", kind='box', order=["No", "Yes"], hue='sex', data=tips)
- bar plot
# kind : 'bar'
# dodge : 집단 막대 그래프를 나누어서 그림(default:True)
sns.catplot(x="smoker", y="tip", kind='bar', hue='sex', dodge=False, data=tips)
- count plot
sns.countplot(tips['sex'])
728x90
'데이터분석' 카테고리의 다른 글
RMSE, Grid Search python 구현 (0) | 2020.11.12 |
---|---|
Logistic Regression (0) | 2020.11.12 |
데이터 전처리 python (0) | 2020.11.12 |
python 복사 단순 객체복사 vs shallow copy vs deep copy (0) | 2020.10.19 |
Python fire package (0) | 2020.10.19 |
댓글