본문 바로가기

Data/Data Visualization

[Seaborn] seaborn scatter tutorial

반응형

참고: https://seaborn.pydata.org/tutorial/relational.html

 

Visualizing statistical relationships — seaborn 0.9.0 documentation

Scatter plots are highly effective, but there is no universally optimal type of visualiation. Instead, the visual representation should be adapted for the specifics of the dataset and to the question you are trying to answer with the plot. With some datase

seaborn.pydata.org

 

 

 

In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style="darkgrid")
In [7]:
tips = sns.load_dataset('tips')
tips.head(10)
Out[7]:
  total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4
5 25.29 4.71 Male No Sun Dinner 4
6 8.77 2.00 Male No Sun Dinner 2
7 26.88 3.12 Male No Sun Dinner 4
8 15.04 1.96 Male No Sun Dinner 2
9 14.78 3.23 Male No Sun Dinner 2
In [3]:
sns.relplot(x='total_bill', y='tip', data=tips)
Out[3]:
<seaborn.axisgrid.FacetGrid at 0x7ff0b1d74390>
 
 

라벨링을 매기고싶다면 relplot의 hue변수를 이용

In [4]:
sns.relplot(x= 'total_bill', y='tip', hue='smoker', data=tips)
Out[4]:
<seaborn.axisgrid.FacetGrid at 0x7ff0b1af2fd0>
 
 

라벨링과 더불어 마크유형도 바꾸고싶다면 style변수를 이용

In [5]:
sns.relplot(x= 'total_bill', y='tip', hue='smoker', style='smoker', data=tips)
Out[5]:
<seaborn.axisgrid.FacetGrid at 0x7ff070ab4b70>
 
 

마크유형을 다른 column정보를 이용하여 변형이 가능함

In [6]:
sns.relplot(x= 'total_bill', y='tip', hue='smoker', style='time', data=tips)
Out[6]:
<seaborn.axisgrid.FacetGrid at 0x7ff0b1cbf9e8>
 
 

column에서 카테고리형이 아닌 변수형에도 적용이 가능

In [8]:
sns.relplot(x= 'total_bill', y='tip', hue='size', data=tips)
Out[8]:
<seaborn.axisgrid.FacetGrid at 0x7ff080af3b38>
 
 

hue는 카테고리를 지정하고, size변수는 변수형타입일때 표시해주는 크기를 설정해줌

In [9]:
sns.relplot(x= 'total_bill', y='tip', size='size', data=tips)
Out[9]:
<seaborn.axisgrid.FacetGrid at 0x7ff0b20ff780>
 
 

size변수를 이용할때 원 크기를 조정이 가능함

In [10]:
sns.relplot(x= 'total_bill', y='tip', size='size', sizes=(15,200), data=tips)
Out[10]:
<seaborn.axisgrid.FacetGrid at 0x7ff070b94358>
 
반응형

'Data > Data Visualization' 카테고리의 다른 글

[Seaborn] seaborn line plotting tutorial  (1) 2019.12.22
[Seaborn] seaborn 라이브러리 연습  (0) 2019.12.22