본문 바로가기

Data/Data Visualization

[Seaborn] seaborn 라이브러리 연습

반응형

 

 

In [12]:
import seaborn as sns
import pandas as pd
import numpy as np
In [2]:
sns.__version__
Out[2]:
'0.9.0'
In [3]:
sns.set()
sns.set_style('whitegrid')
sns.set_color_codes()
In [4]:
current_palette = sns.color_palette()
sns.palplot(current_palette)
 
In [5]:
tips = sns.load_dataset("tips")
In [17]:
tips.head(10)
Out[17]:
  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
 

relplot

In [8]:
sns.relplot(x='total_bill', y = 'tip', hue = 'smoker', style = 'smoker', data=tips)
Out[8]:
<seaborn.axisgrid.FacetGrid at 0x7fd120c69898>
 
In [15]:
df = pd.DataFrame(dict(time=np.arange(500), value=np.random.randn(500).cumsum()))
g = sns.relplot(x='time', y='value', kind= 'line', data=df)
g.fig.autofmt_xdate()
 
 

catplot

In [16]:
sns.catplot(x='day', y='total_bill', hue='smoker',
           col='time', aspect=.6,
           kind = 'swarm', data = tips)
Out[16]:
<seaborn.axisgrid.FacetGrid at 0x7fd140964f60>
 
In [19]:
titanic = sns.load_dataset('titanic')
g = sns.catplot(x='fare', y='survived', row='class', kind='box', orient='h', height=1.5, aspect=4,
               data=titanic.query('fare > 0'))
g.set(xscale='log');
 
 

pairplot

In [21]:
iris = sns.load_dataset('iris')
sns.pairplot(iris, hue = 'species')
Out[21]:
<seaborn.axisgrid.PairGrid at 0x7fd140cf7940>
 
In [22]:
sns.pairplot(iris, hue='species', palette='husl')
Out[22]:
<seaborn.axisgrid.PairGrid at 0x7fd0f0ce2b70>
 
In [23]:
sns.pairplot(iris, vars=['sepal_width', 'sepal_length'])
Out[23]:
<seaborn.axisgrid.PairGrid at 0x7fd16150ae48>
 
 

Heatmap

In [27]:
from matplotlib import pyplot as plt

flights = sns.load_dataset('flights')
flights = flights.pivot('month', 'year', 'passengers')
plt.figure(figsize=(15, 15))
ax = sns.heatmap(flights, annot=True, fmt='d')
 
반응형

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

[Seaborn] seaborn line plotting tutorial  (1) 2019.12.22
[Seaborn] seaborn scatter tutorial  (0) 2019.12.22