You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Matplotlib中导入数值与概率绘制累积分布函数及生存函数?

Cumulative Distribution & Survival Function Visualization

I built a plot that displays both the cumulative distribution and survival function for a dataset using NumPy and Matplotlib. Here's the full code implementation, plus a quick breakdown of what each part does:

import numpy as np
import matplotlib.pyplot as plt

# Calculate histogram bins and corresponding values from the dataset
values, base = np.histogram(serWEB, bins=100)
# Compute cumulative counts for the distribution
cumulative = np.cumsum(values)

# Plot the cumulative distribution function (CDF) in blue
plt.plot(base[:-1], cumulative, c='blue')
plt.title('Cumulative Distribution & Survival Function')
plt.xlabel('X Data')
plt.ylabel('Count')

# Plot the survival function (total observations minus cumulative counts) in green
plt.plot(base[:-1], len(serWEB)-cumulative, c='green')
plt.show()

Key Observations:

  • The blue line shows the cumulative distribution: it tracks how many observations fall at or below each value in the dataset.
  • The green line represents the survival function, which tells you how many observations remain above each value (calculated by subtracting cumulative counts from the total number of entries in serWEB).
  • This plot centers entirely on the numerical distribution of the data, making it straightforward to compare these two complementary metrics at a glance.

内容的提问来源于stack exchange,提问作者Mark Ginsburg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 06:43:57