Cdf draw with python and histograms

Cdf draw with python and histograms

# -*- coding: utf-8 -*-
"""
Created on Fri Dec 20 10:13:27 2019
@author: Ding
"""
import numpy as np
import statsmodels.api as sm # recommended import according to the docs
import matplotlib.pyplot as plt
data=[14.27,14.80,12.28,17.09,15.10,12.92,15.56,15.38,
      15.15,13.98,14.90,15.91,14.52,15.63,13.83,13.66,
      13.98,14.47,14.65,14.73,15.18,14.49,14.56,15.03,
      15.40,14.68,13.33,14.41,14.19,15.21,14.75,14.41,
      14.04,13.68,15.31,14.32,13.64,14.77,14.30,14.62,
      14.10,15.47,13.73,13.65,15.02,14.01,14.92,15.47,
      13.75,14.87,15.28,14.43,13.96,14.57,15.49,15.13,
      14.23,14.44,14.57]
#=============绘制cdf图===============
ecdf = sm.distributions.ECDF(data)
#等差数列,用于绘制X轴数据
x = np.linspace(min(data), max(data))
# x轴数据上值对应的累计密度概率
y = ecdf(x)
#绘制阶梯图
plt.step(x, y)
plt.show()
#===============绘制条形图=============
fig,ax0 = plt.subplots(nrows=1,figsize=(6,6))
#第二个参数是柱子宽一些还是窄一些,越大越窄越密
ax0.hist(data,10,density=1,histtype='bar',facecolor='yellowgreen',alpha=0.75)

Figure cdf
Histogram

Published 68 original articles · won praise 36 · views 10000 +

Guess you like

Origin blog.csdn.net/dingdingdodo/article/details/103641318