python读取plt文件吗_用Python读取文件并绘制CDF

本文介绍如何使用Python的numpy和matplotlib库来读取数据并绘制累积分布函数(CDF)。通过设置箱子边缘,计算每个点在bin中的出现次数,并标准化,从而得到CDF。还展示了如何使用scipy的interp1d进行线性或三次样条插值,以获得连续的CDF函数。
摘要由CSDN通过智能技术生成

为了完整起见,您还应考虑:重复:您可以在数据中多次拥有同一点。

点之间可以有不同的距离

点可以浮动

您可以使用numpy.histogram,以这样的方式设置箱子边缘,即每个箱子只收集一个点的所有出现。

您应该保留density=False,因为根据文档:Note that the sum of the histogram values will not be equal to 1 unless bins of unity width are chosen

您可以规范化每个bin中的元素数除以数据大小。import numpy as np

import matplotlib.pyplot as plt

def cdf(data):

data_size=len(data)

# Set bins edges

data_set=sorted(set(data))

bins=np.append(data_set, data_set[-1]+1)

# Use the histogram function to bin the data

counts, bin_edges = np.histogram(data, bins=bins, density=False)

counts=counts.astype(float)/data_size

# Find the cdf

cdf = np.cumsum(counts)

# Plot the cdf

plt.plot(bin_edges[0:-1], cdf,linestyle='--', marker="o", color

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值