pip install seaborn
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
# matplotlib inline
get_ipython().run_line_magic('matplotlib', 'inline')
sns.set_style('white')
plt.figure(figsize = (10, 6))
plt.plot(x, y1, x, y2, x, y3, x, y4)
sns.despine()
plt.show()
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()
data : seaborn ๋ด์ฅ ์ค์ต ๋ฐ์ดํฐ
tips = sns.load_dataset('tips')
tips.head()
plt.figure(figsize = (8, 6))
sns.boxplot(x = tips['total_bill'])
plt.show()
plt.figure(figsize = (8, 6))
sns.boxplot(x = 'day', y = 'total_bill', data = tips)
plt.show()
plt.figure(figsize = (8, 6))
sns.boxplot(x = 'day', y = 'total_bill', hue = 'smoker', data = tips, palette= 'Set3')
plt.show()
plt.figure(figsize = (8, 6))
sns.swarmplot(x = 'day', y = 'total_bill', hue = 'smoker', data = tips)
plt.show()
sns.lmplot(x = 'total_bill', y = 'tip', data = tips)
plt.show()
sns.lmplot(x = 'total_bill', y = 'tip', hue = 'smoker', data = tips)
plt.show()
Data
flights = sns.load_dataset('flights')
flights.head()
flights = flights.pivot(index = ['month'], columns=['year'], values=['passengers'])
flights.head()
plt.figure(figsize = (10, 6))
sns.heatmap(flights, annot = True, fmt = 'd')
plt.show()
plt.figure(figsize = (10, 6))
sns.heatmap(flights, annot = True, fmt = 'd', cmap = 'YlGnBu')
plt.show()
data
sns.set(style = 'ticks')
iris = sns.load_dataset('iris')
iris.head()
sns.pairplot(iris)
plt.show()
sns.pairplot(iris, hue = 'species') # ํน์ฑ๋ณ ์๊ด๊ด๊ณ ์ฆ์ ํ์
plt.show()
sns.pairplot(iris, x_vars = ['sepal_width', 'sepal_length'], y_vars = ['petal_width', 'petal_length'], hue = 'species') # ํน์ฑ๋ณ ์๊ด๊ด๊ณ ์ฆ์ ํ์
plt.show()
Data
anscombe = sns.load_dataset('anscombe')
anscombe.head()
sns.set_style('darkgrid')
sns.lmplot(x = 'x', y='y', data = anscombe.query('dataset == "I"'), ci = None)
sns.set_style('darkgrid')
sns.lmplot(x = 'x', y='y', data = anscombe.query('dataset == "I"'), ci = None, scatter_kws={'s':80}) # scatter_kws : ๋ง์ปค์ฌ์ด์ฆ ๋ณ๊ฒฝ
sns.set_style('darkgrid')
sns.lmplot(x = 'x', y='y', data = anscombe.query('dataset == "II"'), ci = None, order = 2, scatter_kws={'s':80}) # order : n์ฐจ์ ๋ณ๊ฒฝ
sns.set_style('darkgrid')
sns.lmplot(x = 'x', y='y', data = anscombe.query('dataset == "III"'), ci = None, order = 2, scatter_kws={'s':80}) # order : n์ฐจ์ ๋ณ๊ฒฝ