天天看点

python distplot 图_seaborn实例-distplot-直方图

好了,这次来看看seaborn中的直方图

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)

Flexibly plot a univariate distribution of observations.

关于频率分布直方图,我一开始没搞懂纵坐标是啥,可以参考:

小栗子

主要的,就是我们要传入一个观测数据

python distplot 图_seaborn实例-distplot-直方图

data = np.random.randint(10,100,100)

sns.distplot(data)

python distplot 图_seaborn实例-distplot-直方图

好了,我们来看一下这个图

因为我们只传入了观测数据,所以是自动分组的

这个seaborn也有个问题,就是我无法获得它分的组,如果是使用matplotlib的话,是可以返回的

按道理说这个图形的面积应该是1,

为了简单,我们来指定下分组数,我们就分成1组,哈哈哈

sns.distplot(data , bins=1)

python distplot 图_seaborn实例-distplot-直方图

然后,我们计算下其他指标,组距的话,就是最大值-最小值

data.max()-data.min()

python distplot 图_seaborn实例-distplot-直方图

频率就是1,所以,纵坐标是1/87,差不多是

python distplot 图_seaborn实例-distplot-直方图

就是这个图的嘛,恩不错

其他的几个参数,可以试试,暂时就看了官方的介绍,后面应用在补充吧