CDS

Data Visulization : Seaborn(데이터 시각화)

juju824 2021. 11. 12. 17:37

📌Seaborn

matplotlib를 기반으로 하는 Python visualization library, attractive한 통계적 그래프를 제공함 

✔️ 공식 : http://seaborn.pydata.org 

 

seaborn: statistical data visualization — seaborn 0.11.2 documentation

Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. For a brief introduction to the ideas behind the library, you can read the introductory note

seaborn.pydata.org

 

Seaborn을 import하면 색상 등의 스타일을 Matplotlib에서 제공하는 기본 스타일이 아니라 Seabon에서 지정한 기본 스타일로 바꿔진다 

더 다채롭게 그래프, 데이터 시각화를 가능케 하는 라이브러리로 보인다 

 

👉 Seaborn을 이용하여 그래프 그리기

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

import seaborn as sns		#Seaborn import함

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=(10, 6))
plt.plot(x, y1, x, y2, x, y3, x, y4)
plt.show()

결과로 나온 그래프 그림을 보아하니,

y1은 파란색 그래프, y2는 주황, y3는 초록, y4는 빨간색 그래프를 뜻하는 걸로 보인다 

plt.figure를 통해 10*6 size의 바탕 네모칸을 지정, 

plt.plot에 각각 x,y를 넣어줌으로써 마지막에 show()를 통해 보여지게 됨 

 

 

sns.set_style("dark")
plt.figure(figsize=(10, 6))
plt.plot(x, y1, x, y2, x, y3, x, y4)
plt.show()

 

sns.set_style("whitegrid")
sns.despine(offset=10)
plt.figure(figsize=(10, 6))
plt.plot(x, y1, x, y2, x, y3, x, y4)
plt.show()

👉 sns.set_style("style you pick")

: 본인이 원한 스타일에 맞춰서 그래프가 바뀌게 된다. dark 적용하면 배경색이 dark로, whitegrid적용하면 배경이 흰색 누금자 바탕으로 변경됨 

'CDS' 카테고리의 다른 글

Machine Learning [K-NN]  (0) 2021.11.15
Machine Learning [Scikit-Learn]  (0) 2021.11.15
Machine Learning Overview  (0) 2021.11.15
Data Visulization : Matplotlib(데이터 시각화)  (0) 2021.11.12
EDA (Exploratory Data Analysis)  (0) 2021.11.12