日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python distplot 图_Python可视化23 |seaborn.distplot公司单变量分布图(直方图|核密度图),23seaborndistplot...

發(fā)布時間:2023/12/4 python 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python distplot 图_Python可视化23 |seaborn.distplot公司单变量分布图(直方图|核密度图),23seaborndistplot... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

本文介紹seaborn.distplot繪制

單變量分布圖

之前文章介紹的

核密度圖

(kernel density estimate (KDE))以及

二者結(jié)合圖。

目錄

本文內(nèi)容概要

直方圖

核密度圖

直方圖結(jié)合核密度圖

1、seaborn.distplot

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)

http://seaborn.pydata.org/generated/seaborn.distplot.html#seaborn.distplot

整合了如下三個函數(shù):

matplotlib中的直方圖hist(默認(rèn)繪制直方圖)

seaborn.kdeplot()

seaborn.rugplot()

scipy.stats

數(shù)據(jù)準(zhǔn)備

import seaborn as sns

import numpy as np

import matplotlib.pyplot as plt

np.random.seed(0)

x=np.random.randn(100)#造一個shape為(100,),服從正態(tài)分布的對象x

print(x)

print(x.shape)

繪制直方圖hist

plt.figure(dpi=120)

sns.set(style='dark')

sns.set_style("dark", {"axes.facecolor": "#e9f3ea"})#修改背景色

g=sns.distplot(x,

hist=True,#默認(rèn)繪制直方圖,詳細(xì)參考plt.hist

kde=False,

color="#098154")#修改柱子顏色

修改直方圖hist中箱子數(shù)bins

plt.figure(dpi=120)

sns.set(style='dark')

sns.set_style("dark", {"axes.facecolor": "#e9f3ea"})

g=sns.distplot(x,

hist=True,

bins=15,#修改箱子個數(shù)

kde=False,

color="#098154")

直方圖成箱方式

有4種方式:'bar,barstacked,step,stepfilled'。

sns.set(style='dark')

sns.set_style("dark", {"axes.facecolor": "#e9f3ea"})

for i in list('bar,barstacked,step,stepfilled'.split(',')):

plt.figure(dpi=120)

sns.distplot(x,

hist=True,

bins=15,

kde=False,

hist_kws={'histtype':'%s'%i}, #默認(rèn)為bar,可選barstacked,step,stepfilled

color="#098154")

plt.title("histtype="'%s'%i)

plt.show()

繪制核密度曲線kernel density estimate (KDE)

plt.figure(dpi=120)

sns.set(style='dark')

sns.set_style("dark", {"axes.facecolor": "#e9f3ea"})

g=sns.distplot(x,

hist=False,

kde=True,#開啟核密度曲線kernel density estimate (KDE)

kde_kws={'linestyle':'--','linewidth':'1','color':'#098154',#設(shè)置外框線屬性

'shade':True,#開啟填充

},

)

seaborn.kdeplot繪制窄寬度核密度曲線

plt.figure(dpi=120)

sns.set(style='dark')

sns.set_style("dark", {"axes.facecolor": "#e9f3ea"})#修改背景色

g=sns.kdeplot(x,

shade=True,

bw=0.15,#使用窄帶寬

color="#098154"

)

bandwidth (bw),控制核密度曲線胖瘦

類似hist中bin size

plt.figure(dpi=120)

sns.set(style='dark')

sns.set_style("dark", {"axes.facecolor": "#e9f3ea"})

sns.kdeplot(x,shade=True, label="bw: defult")

sns.kdeplot(x, bw=.2, label="bw: 0.2")

sns.kdeplot(x, bw=2, label="bw: 2")

plt.legend();

核密度曲線結(jié)合直方圖

plt.figure(dpi=120)

sns.set(style='dark')

sns.set_style("dark", {"axes.facecolor": "#e9f3ea"})

g=sns.distplot(x,

hist=True,

kde=True,#開啟核密度曲線kernel density estimate (KDE)

kde_kws={'linestyle':'--','linewidth':'1','color':'#c72e29',#設(shè)置外框線屬性

},

color='#098154',

axlabel='Xlabel',#設(shè)置x軸標(biāo)題

)

fit參數(shù)

將數(shù)據(jù)與scipy.stats中的分布擬合,查看數(shù)據(jù)服從何種分布,更多可參考:https://docs.scipy.org/doc/scipy/reference/stats.html

from scipy.stats import norm#導(dǎo)入正態(tài)分布

plt.figure(dpi=120)

sns.set(style='dark')

sns.set_style("dark", {"axes.facecolor": "#e9f3ea"})

g=sns.distplot(x,

hist=True,

kde=False,

kde_kws={'linestyle':'--','linewidth':'1','color':'#c72e29',

},

fit=norm,#

color='#098154',

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結(jié)

以上是生活随笔為你收集整理的python distplot 图_Python可视化23 |seaborn.distplot公司单变量分布图(直方图|核密度图),23seaborndistplot...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。