nethunter 2018. 7. 6. 16:24
반응형

Matpoltlib 와 같이 사용

pip install seaborn

Seaborn은 Matplotlib을 기반으로 다양한 색상 테마와 통계용 챠트 등의 기능을 추가한 시각화 패키지이다. 기본적인 시각화 기능은 Matplotlib 패키지에 의존하며 통계 기능은 Statsmodels 패키지에 의존한다.

https://seaborn.github.io/

Seaborn을 임포트하면 색상 등을 Matplotlib에서 제공하는 기본 스타일이 아닌 Seaborn에서 지정한 기본 스타일로 바꾼다. 따라서 동일한 Matplotlib 명령을 수행해도 Seaborn을 임포트 한 것과 하지 않은 플롯은 모양이 다르다.

 

 

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

 

x = np.linspace(0,14,100)

y1 = np.sin(x)
y2 = 2*np.sin(x+0.5)
y3 = 3*np.sin(x+1.0)
y4 = 4*np.sin(x+1.5)

plt.figure(figsize = (5,3))
plt.plot(x,y1, x,y2, x,y3, x,y4)
plt.show()

 

 

 

 

 

 

import seaborn as sns

x = np.linspace(0,14,100)

y1 = np.sin(x)
y2 = 2*np.sin(x+0.5)
y3 = 3*np.sin(x+1.0)
y4 = 4*np.sin(x+1.5)

sns.set_style("whitegrid")

plt.figure(figsize = (5,3))
plt.plot(x,y1, x,y2, x,y3, x,y4)
plt.show()

 

 

 

 

tips = sns.load_dataset('tips')

plt.figure(figsize=(6,3))
sns.boxplot(x="day", y="total_bill", data=tips)
plt.show()

 

 

 

 

 

# lmplot 를 그리면 scatter 처럼 점으로 표시하고 직선으로 regression 한 그름도 같이 표시합니다.

sns.set_style('darkgrid')
sns.lmplot(x='total_bill', y='tip', data=tips, size=7)
plt.show()

 

 

 

 

 

# hue 를 사용하면 카테고리별 그룹핑까지 자동화 해줍니다.

sns.set_style('darkgrid')
sns.lmplot(x='total_bill', y='tip', data=tips, size=7, hue='smoker', palette='Set1')
plt.show()

 

 

 

 

 

반응형