Python 3.x 在Python中规范化CDF

Python 3.x 在Python中规范化CDF,python-3.x,cdf,normalizing,Python 3.x,Cdf,Normalizing,我想计算并绘制给定样本的累积分布函数(CDF),new_dO18,然后将正态分布的CDF与给定的平均值和标准偏差叠加在同一个图上。我无法正常化CDF。x轴上的值应该在0到1之间。有人能告诉我哪里出了错吗。我相信这是一个简单的修复,但我对Python非常陌生。到目前为止,我已经包括了我的步骤。谢谢 # Use np.histogram to get counts in each bin. See the help page or # documentation on how to use this

我想计算并绘制给定样本的累积分布函数(CDF),new_dO18,然后将正态分布的CDF与给定的平均值和标准偏差叠加在同一个图上。我无法正常化CDF。x轴上的值应该在0到1之间。有人能告诉我哪里出了错吗。我相信这是一个简单的修复,但我对Python非常陌生。到目前为止,我已经包括了我的步骤。谢谢

# Use np.histogram to get counts in each bin. See the help page or
# documentation on how to use this function, and what it returns.

# normalize the data new_dO18 using a for loop
norm_newdO18 = []
for element in new_dO18:
    x = element 
    y = (x - np.mean(new_dO18))/np.std(new_dO18)
    norm_newdO18.append(y)
print ('normalized dO18 values, excluding outliers:', norm_newdO18)
print()

# Use the histogram function to bin the data
num_bins = 20
counts, bin_edges = np.histogram(norm_newdO18, bins=num_bins,   normed=0)

# Calculate and plot CDF of sample 
cdf = np.cumsum(counts)
scale = 1.0/cdf[-1]
norm_cdf = scale * cdf

plt.plot(bin_edges[1:], norm_cdf, label = 'dO18 values')
plt.legend(bbox_to_anchor=(0, 1), loc='upper left', ncol=1)
plt.xlabel('normalized dO18 data')
plt.ylabel('frequency')

# Calculate and overlay the CDF of a normal distribution with sample mean and std
# as parameters.

# specific normally distributed function with mean and st. dev 
mu, sigma = np.mean(new_dO18), np.std(new_dO18) 
norm_theoretical = np.random.normal(mu, sigma, 1000)

# Calculate and plot CDF of theoretical sample 
counts1, bin_edges1 = np.histogram(norm_theoretical, bins=20, normed=0)
cdft= np.cumsum(counts1)
scale = 1.0/cdft[-1]
norm_cdft = scale * cdf
plt.plot(bin_edges[1:], norm_cdft, label = 'theoretical values')
plt.legend(bbox_to_anchor=(0, 1), loc='upper left', ncol=1)
plt.show()

为什么不在SciPy中使用离散随机变量呢?另外(因为我们无法访问您的数据),您尝试规范化后的最大CDF是多少?我尝试规范化后的最大CDF是2.5Wait,仓位宽度不是1,是吗?这就是你的罪魁祸首……顺便说一句,你可以通过在调用
np.histogram
时设置
density=True
绕过这一切。为什么不在SciPy中使用离散随机变量呢?另外(因为我们无法访问您的数据),您尝试规范化后的最大CDF是多少?我尝试规范化后的最大CDF是2.5Wait,仓位宽度不是1,是吗?这就是你的罪魁祸首……顺便说一句,你可以通过在调用
np.histogram