Python (Seaborn)

Arsen·2022년 9월 27일
0

Python

목록 보기
3/12
post-thumbnail

Matplotlib내에서 Seaborn을 import하면 자동으로 그래프가
적절하게 바뀜
despine을 적용하면 윤곽선 네개중에 위랑 오른쪽 선이 사라진다.

import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline

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

boxplot-hue

hue로 구분을짓는다.

plt.figure(figsize=(8,6))
sns.boxplot(x="day", y="total_bill", hue="smoker", data=tips, palette="Set3")
plt.show()

swarmplot

boxplot과 swarmplot을 함께 씀으로써 분포와 밀도를 다 알수 있음

plt.figure(figsize=(8,6))
sns.swarmplot(x="day", y="total_bill", data=tips, color=".5")
plt.show()

Implot


sns.set_style("darkgrid")
sns.Implot(x="total_bill", y="tip", data=tips, height=7)
plt.show()

pivot

flights data 불러옴

flights = sns.load_dataset("flights")
flights.head(5)

pivot 적용

flights = flights.pivot("month", "year", "passengers")
flights.head(5)

heatmap 적용

plt.figure(figsize=(10,8))
sns.heatmap(flights, annot=True, fmt="d")
plt.show()

cmap으로 색형식변경할 수 있다.

pairplot

Iris 데이터셋 불러오기

sns.set(style="ticks")
iris = sns.load_dataset("iris")
iris.head(10)

pairplot 적용

sns.pairplot(iris, hue="species")
plt.show()

더 자세히 보기위해

sns.pairplot(iris, x_vars=["sepal_width", "sepal_length"],
			y_vars=["petal_width", "petal_length"],
            hue="species",
            height=4)
plt.show()

seaborn catplot

titanic = sns.load_dataset("titanic")
titanic.head()

sns.catplot(x="sex", y="survived", hue="pclass", data=titanic, kind="bar",
			palette="muted", legend=True, height=7)
plt.show()
profile
ML/AR/CV 공부

0개의 댓글