%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
x = np.linspace(0, 10, 20)
y = x ** 2
plt.plot(x, y)
plt.show()
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import pandas as pd
x = np.linspace(0, 10, 20)
y = x ** 2
sns.set()
plt.plot(x, y)
plt.show()
tips = sns.load_dataset("tips") # sns.load_dataset : seaborn에서 제공하는 데이터 불러오기
sns.relplot(x="total_bill", y="tip", data=tips)
plt.show()
sns.relplot(x="total_bill", y="tip", data=tips)
plt.show()
tips.head(10)
Out[-]
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
titanic = sns.load_dataset("titanic")
f, ax = plt.subplots(figsize=(7, 3))
sns.countplot(y="deck", data=titanic, color="c") # 가로 그래프 생성
# y 대신 x를 사용하면 세로 그래프
titanic.head(10)
Out[-]
survived pclass sex age sibsp parch fare embarked class who adult_male deck embark_town alive alone
0 0 3 male 22.0 1 0 7.2500 S Third man True NaN Southampton no False
1 1 1 female 38.0 1 0 71.2833 C First woman False C Cherbourg yes False
2 1 3 female 26.0 0 0 7.9250 S Third woman False NaN Southampton yes True
3 1 1 female 35.0 1 0 53.1000 S First woman False C Southampton yes False
4 0 3 male 35.0 0 0 8.0500 S Third man True NaN Southampton no True
5 0 3 male NaN 0 0 8.4583 Q Third man True NaN Queenstown no True
6 0 1 male 54.0 0 0 51.8625 S First man True E Southampton no True
7 0 3 male 2.0 3 1 21.0750 S Third child False NaN Southampton no False
8 1 3 female 27.0 0 2 11.1333 S Third woman False NaN Southampton yes False
9 1 2 female 14.0 1 0 30.0708 C Second child False NaN Cherbourg yes False
sns.pairplot(titanic, hue='class')
plt.show()
import plotly.express as px
df = px.data.gapminder().query("country=='Canada'")
fig = px.line(df,
x="year", y="lifeExp",
title='Life expectancy in Canada')
fig.show()