熱線電話:13121318867

登錄
首頁精彩閱讀seaborn 常用的 10 種數據分析圖表
seaborn 常用的 10 種數據分析圖表
2020-04-28
收藏
<a href='/map/seaborn/' style='color:#000;font-size:inherit;'>seaborn</a> 常用的 10 種數據分析圖表


內置示例數據集


seaborn內置了十幾個示例數據集,通過load_dataset函數可以調用。


其中包括常見的泰坦尼克、鳶尾花等經典數據集。


# 查看數據集種類
import seaborn as sns
sns.get_dataset_names()
<a href='/map/seaborn/' style='color:#000;font-size:inherit;'>seaborn</a> 常用的 10 種數據分析圖表
import seaborn as sns
# 導出鳶尾花數據集
data = sns.load_dataset('iris')
data.head()

<a href='/map/seaborn/' style='color:#000;font-size:inherit;'>seaborn</a> 常用的 10 種數據分析圖表


1、散點圖


函數sns.scatterplot


import seaborn as sns
sns.set()
import matplotlib.pyplot as plt
%matplotlib inline
# 小費數據集
tips = sns.load_dataset('tips')
ax = sns.scatterplot(x='total_bill',y='tip',data=tips)
plt.show()

<a href='/map/seaborn/' style='color:#000;font-size:inherit;'>seaborn</a> 常用的 10 種數據分析圖表


2、條形圖


函數sns.barplot


顯示數據平均值和置信區間


import seaborn as sns
sns.set()
import matplotlib.pyplot as plt
%matplotlib inline
# 小費數據集
tips = sns.load_dataset("tips")
ax = sns.barplot(x="day", y="total_bill", data=tips)
plt.show()

<a href='/map/seaborn/' style='color:#000;font-size:inherit;'>seaborn</a> 常用的 10 種數據分析圖表


3、線型圖


函數sns.lineplot


繪制折線圖和置信區間


import seaborn as sns
sns.set()
import matplotlib.pyplot as plt
%matplotlib inline
fmri = sns.load_dataset("fmri")
ax = sns.lineplot(x="timepoint", y="signal", data=fmri)
plt.show()
<a href='/map/seaborn/' style='color:#000;font-size:inherit;'>seaborn</a> 常用的 10 種數據分析圖表


4、箱線圖


函數seaborn.boxplot


import seaborn as sns
sns.set()
import matplotlib.pyplot as plt
%matplotlib inline
tips = sns.load_dataset("tips")
ax = sns.boxplot(x="day", y="total_bill", data=tips)
plt.show()
<a href='/map/seaborn/' style='color:#000;font-size:inherit;'>seaborn</a> 常用的 10 種數據分析圖表


5、直方圖


函數seaborn.distplot


import seaborn as sns
import numpy as np
sns.set()
import matplotlib.pyplot as plt
%matplotlib inline
np.random.seed(0)
x = np.random.randn(1000)
ax = sns.distplot(x)
plt.show()
<a href='/map/seaborn/' style='color:#000;font-size:inherit;'>seaborn</a> 常用的 10 種數據分析圖表


6、熱力圖


函數seaborn.heatmap


import numpy as np
np.random.seed(0)
import seaborn as sns 
sns.set()
import matplotlib.pyplot as plt
%matplotlib inline
uniform_data = np.random.rand(10, 12)
ax = sns.heatmap(uniform_data)
plt.show()
<a href='/map/seaborn/' style='color:#000;font-size:inherit;'>seaborn</a> 常用的 10 種數據分析圖表


7、散點圖矩陣


函數sns.pairplot


import seaborn as sns
sns.set()
import matplotlib.pyplot as plt
%matplotlib inline
iris = sns.load_dataset("iris")
ax = sns.pairplot(iris)
plt.show()

<a href='/map/seaborn/' style='color:#000;font-size:inherit;'>seaborn</a> 常用的 10 種數據分析圖表


8、分類散點圖


函數seaborn.catplot


import seaborn as sns
sns.set()
import matplotlib.pyplot as plt
%matplotlib inline
exercise = sns.load_dataset("exercise")
ax = sns.catplot(x="time", y="pulse", hue="kind", data=exercise)\
plt.show()
<a href='/map/seaborn/' style='color:#000;font-size:inherit;'>seaborn</a> 常用的 10 種數據分析圖表


9、計數條形圖


函數seaborn.countplot


import seaborn as sns
sns.set()
import matplotlib.pyplot as plt
%matplotlib inline
titanic = sns.load_dataset("titanic")
ax = sns.countplot(x="class", data=titanic)
plt.show()

<a href='/map/seaborn/' style='color:#000;font-size:inherit;'>seaborn</a> 常用的 10 種數據分析圖表


10、回歸圖


函數 seaborn.lmplot


繪制散點及回歸圖


import seaborn as sns
sns.set()
import matplotlib.pyplot as plt
%matplotlib inline
tips = sns.load_dataset("tips")
ax = sns.lmplot(x="total_bill", y="tip", data=tips)

plt.show()
<a href='/map/seaborn/' style='color:#000;font-size:inherit;'>seaborn</a> 常用的 10 種數據分析圖表

數據分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數據分析師資訊
更多

OK
客服在線
立即咨詢
日韩人妻系列无码专区视频,先锋高清无码,无码免费视欧非,国精产品一区一区三区无码
客服在線
立即咨詢