import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
lst = np.random.normal(0, 10, 200)
plt.figure(figsize=(12, 3))
plt.hist(lst, bins=30)
plt.title("hist in matplolib", fontsize='xx-large')
plt.savefig('../../assets/images/markdown_img/180604_not_applied_seaborn.svg')
plt.show()
plt.figure(figsize=(12, 3))
sns.distplot(lst, bins=30, rug=True)
plt.title("hist in seaborn", fontsize='xx-large')
plt.savefig('../../assets/images/markdown_img/180604_applied_seaborn.svg')
plt.show()
sample_size = 1000
X = np.random.normal(0, 1, sample_size)
Y = X + np.random.normal(0, 1, sample_size)
sns.jointplot(X, Y, marker='o', kind='reg')
plt.savefig("../../assets/images/markdown_img/180605_sns_jointplot_reg.svg")
plt.show()
sns.jointplot(X, Y, kind='hex')
plt.savefig("../../assets/images/markdown_img/180605_sns_jointplot_hex.svg")
plt.show()
sns.jointplot(X, Y, kind='kde')
plt.savefig("../../assets/images/markdown_img/180605_sns_jointplot_kde.svg")
plt.show()
iris = sns.load_dataset("iris")
print(iris.head())
sns.pairplot(iris,
hue='species',
palette="husl",
kind='reg',
markers='+',
diag_kws={'bins':20},
plot_kws={}
)
plt.savefig("../../assets/images/markdown_img/180604_pairplot_with_hue.svg")
plt.show()
sepal_length sepal_width petal_length petal_width species
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
heatmap_df = pd.DataFrame(np.random.normal(0, 1, 100).reshape(10, 10),
columns=['col_{}'.format(i) for i in range(0, 10)],
index=['col_{}'.format(i) for i in range(0, 10)]
)
"""
- True인 경우, 표시되지 않고, False인 경우만 표시됨
- mask는 df의 형태로 넘길 수 있음.
"""
mask = heatmap_df.applymap(lambda x: True if abs(x)<1.0 else False)
print(mask)
plt.figure(figsize=(12, 10))
sns.heatmap(heatmap_df, annot=True,
fmt=".1f",
#cmap=plt.cm.Blues,
mask=mask,
cbar=True,
linewidths=3)
plt.tick_params(labelsize=13)
plt.gca().xaxis.tick_top()
plt.xticks(rotation=45)
plt.yticks(rotation=0)
plt.savefig('../../assets/images/markdown_img/180605_heatmap_sns.svg')
plt.show()
col_0 col_1 col_2 col_3 col_4 col_5 col_6 col_7 col_8 col_9
col_0 True False True False True True False True False True
col_1 True True True True True False True True True True
col_2 True False False True False False True False True True
col_3 True True True True True False True True True True
col_4 True True True True False True True True False True
col_5 True True False False True True False False True True
col_6 True True False False False True True True True True
col_7 True True True True True True True True False True
col_8 True False False True False False True True True True
col_9 True True True True True True True True True False
댓글남기기