Primer..
6
从我在你@Warren Weckesser原来答案理解下文称到 "所有你需要做的"是:
写的近似cdf(b) - cdf(a)为
cdf(b) - cdf(a) = pdf(m)*(b - a)
其中m为,比如说,在时间间隔的中点[A,B]
我们可以尝试遵循他的建议,并根据箱子的中心点绘制两种获取pdf值的方法:
具有PDF功能
具有CDF功能:
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
# generate log-normal distributed set of samples
np.random.seed(42)
samples = np.random.lognormal(mean=1, sigma=.4, size=10000)
N_bins = 50
# make a fit to the samples
shape, loc, scale = stats.lognorm.fit(samples, floc=0)
x_fit = np.linspace(samples.min(), samples.max(), 100)
samples_fit = stats.lognorm.pdf(x_fit, shape, loc=loc, scale=scale)
# plot a histrogram with linear x-axis
fig, (ax1, ax2) = plt.subplots(1,2, figsize=(10,5), gridspec_kw={'wspace':0.2})
counts, bin_edges, ignored = ax1.hist(samples, N_bins, histtype='stepfilled', alpha=0.4,
label='histogram')
# calculate area of histogram (area under PDF should be 1)
area_hist = ((bin_edges[1:] - bin_edges[:-1]) * counts).sum()
# plot fit into histogram
ax1.plot(x