seaborn Published by onesixx on 21-07-09 21-07-09
relation plots : 두 변수의 관계를 나타냄 종류 : relplot, scatterplot, lineplot
categorical plots : 범주형 데이터를 대상으로 함 종류 : catplot, stripplot, swarmplot, boxplot, violinplot, boxenplot, pointplot, barplot, countplot
distribution plots : 변수들의 분포를 나타냄 종류 : displot, hisplot, kdeplot, ecdfplot, rugplot, distplot
regression plots : 회귀분석 결과를 나타내줌 종류 : Implot, regplot, residplot
matrix plots : 변수 간의 관계 정도를 매트릭스로 만들고 색을 입혀 나타냄 종류 : heatmap, clustermap
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_context( 'paper' ) # notebook, paper, poster : font line marker 요소 배율 설정
sns.set_palette(sns.color_palette( "colorblind" )) # Set1, color_palette() 등
sns.set_style( "whitegrid" )
tips = sns.load_dataset( "tips" )
for col in tips.columns:
if pd.api.types.is_numeric_dtype(tips[col]):
tips[col] = pd.to_numeric(tips[col], errors = 'coerce' ) # NaN으로 변환 raise/ignore/coerce
fig, ax = plt.subplots( figsize = ( 12 , 8 ))
ax.hist(tips[col], bins = 20 , color = 'skyblue' , edgecolor = 'black' )
ax.set(
xlabel = col, ylabel = 'Frequency' ,
title = f 'Histogram of { col.capitalize() } '
)
else :
#** not numeric"
fig, ax = plt.subplots( figsize = ( 12 , 8 ))
sns.countplot( data = tips, x = col, ax = ax)
ax.set( title = f 'Count of { col.capitalize() } ' )
sns.relplot(
data = tips,
x = "total_bill" ,
y = "tip" ,
row = "sex" ,
col = "time" , #col_wrap=3,
hue = "day" , palette = [ 'g' , 'y' , 'b' , "r" ],
style = "smoker" ,
size = "size" , sizes = ( 10 , 100 ),
#color="blue",
kind = "scatter" ,
height = 5 , aspect = 1
)
flights = sns.load_dataset( "flights" )
flights_wide = flights.pivot( index = "year" , columns = "month" , values = "passengers" )
sns.relplot( data = flights, x = "year" , y = "passengers" , hue = 'month' , style = 'month' , kind = "line" )
sns.relplot( data = flights_wide, kind = "line" ) # same