分布圖包括單變量核密度曲線,直方圖,雙變量多變量的聯合直方圖,和密度圖
1.單分布
(1)直方圖distpot
seaborn.distplot(a, bins=None, hist=True, kde=True, rug=False, fit=None, hist_kws=None, kde_kws=None, rug_kws=None, fit_kws=None, color=None, vertical=False, norm_hist=False, axlabel=None, label=None, ax=None)
- 設置
kde=False
則可以只繪制直方圖,或者hist=False
只繪制核密度估計圖
舉例:
sns.distplot(iris["sepal_length"])
(2)核函數密度估計圖kdeplot
seaborn.kdeplot(data, data2=None, shade=False, vertical=False, kernel='gau', bw='scott', gridsize=100, cut=3, clip=None, legend=True, cumulative=False, shade_lowest=True, cbar=False, cbar_ax=None, cbar_kws=None, ax=None, **kwargs)
kdeplot
可以專門用於繪制核密度估計圖,其效果和distplot(hist=False)
一致,但kdeplot
擁有更多的自定義設置
舉例:
sns.kdeplot(iris["sepal_length"])
2.雙分布
(1)二元變量分布圖jointplot
seaborn.jointplot(x, y, data=None, kind='scatter', stat_func=None, color=None, height=6, ratio=5, space=0.2, dropna=True, xlim=None, ylim=None, joint_kws=None, marginal_kws=None, annot_kws=None, **kwargs)
jointplot
並不是一個 Figure-level 接口,但其支持kind=
參數指定繪制出不同樣式的分布圖。例如,繪制出核密度估計對比圖 kind = 'kde'。- kind='hex'繪制六邊形計數圖
- kind='reg'繪制回歸擬合圖
舉例:
例如,我們探尋 sepal_length
和 sepal_width
二元特征變量之間的關系。
sns.jointplot(x="sepal_length", y="sepal_width", data=iris)
(2)變量關系組圖pairpot
支持將數據集中的特征變量兩兩對比繪圖,默認情況下,對角線上是單變量分布圖,而其他是二元變量分布圖
seaborn.pairplot(data, hue=None, hue_order=None, palette=None, vars=None, x_vars=None, y_vars=None, kind='scatter', diag_kind='auto', markers=None, height=2.5, aspect=1, dropna=True, plot_kws=None, diag_kws=None, grid_kws=None, size=None)
舉例:
sns.pairplot(iris, hue="species")
(3)將數組中的數據點繪制為軸上的數據rugplot
seaborn.rugplot(a, height=0.05, axis='x', ax=None, **kwargs)