"""
Created on Tue Mar 12 22:09:09 2024
@author: zhang
"""
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
mean,std=1,0.3
sample_size=2000
# logNorm distribution
samples=np.exp(stats.norm.rvs(mean,std,size=sample_size))
res=stats.relfreq(samples,numbins=20)
pdf_value=res.frequency
cdf_value=np.cumsum(res.frequency)
x=res.lowerlimit+np.linspace(0,res.binsize*res.frequency.size,res.frequency.size)
fig,(ax1,ax2)=plt.subplots(2,1,figsize=(5,6))
ax1.set_xlabel('Frequency (MHz)')
ax1.set_ylabel('Probability')
ax1.hist(samples,15,density=True)
ax1.set_xlim([x.min(),x.max()])
ax1.grid(True,linestyle='--',alpha=0.4)
ax2.set_xlabel('Frequency (MHz)')
ax2.set_ylabel('Cumulative Probability')
ax2.plot(x,cdf_value)
ax2.grid(True,linestyle='--',alpha=0.4)
plt.show()
代码运行后结果为: