帕累托分布 密度函数 和 分布函数

帕累托分布 密度函数 和 分布函数 importnumpy as npimportmatplotlib.pyplot as plt# 屏幕显示和默认保存分辨率plt.rcParams.update({figure.dpi:180,savefig.dpi:600,font.size:14,axes.titlesize:17,axes.labelsize:15,legend.fontsize:12,xtick.labelsize:12,ytick.labelsize:12,lines.linewidth:2.5,})# --------------------------------------------------# Parameters# --------------------------------------------------x_m1.0alphas[0.5,1.0,1.5,2.0,3.0,5.0,10.0]xnp.geomspace(x_m,100,5000)def pareto_pdf(x, x_m, alpha):returnalpha * x_m**alpha / x**(alpha 1)def pareto_cdf(x, x_m, alpha):return1-(x_m / x)**alpha def pareto_survival(x, x_m, alpha):return(x_m / x)**alpha# 增大画布fig, axesplt.subplots(1,3,figsize(21,7),constrained_layoutTrue)colorsplt.cm.viridis(np.linspace(0,0.95, len(alphas)))foralpha, colorinzip(alphas, colors): labelrf$\alpha{alpha}$axes[0].plot(x, pareto_pdf(x, x_m, alpha),colorcolor,labellabel)axes[1].plot(x, pareto_cdf(x, x_m, alpha),colorcolor,labellabel)axes[2].loglog(x, pareto_survival(x, x_m, alpha),colorcolor,labellabel)# PDFaxes[0].set_xlim(x_m,10)axes[0].set_ylim(bottom0)axes[0].set_xlabel(r$x$)axes[0].set_ylabel(r$f(x)$)axes[0].set_title(Probability density function)axes[0].grid(True,alpha0.3)axes[0].legend()# CDFaxes[1].set_xscale(log)axes[1].set_ylim(0,1.02)axes[1].set_xlabel(r$x$ (log scale))axes[1].set_ylabel(r$F(x)P(X\leq x)$)axes[1].set_title(Cumulative distribution function)axes[1].grid(True,whichboth,alpha0.3)axes[1].legend()# Survival functionaxes[2].set_xlabel(r$x$ (log scale))axes[2].set_ylabel(r$P(Xx)$ (log scale))axes[2].set_title(Tail probability)axes[2].grid(True,whichboth,alpha0.3)axes[2].legend()fig.suptitle(rfPareto distributions with different $\alpha$,$x_m{x_m}$,fontsize20)# 600 DPI高清PNGfig.savefig(pareto_different_alphas_600dpi.png,dpi600,bbox_inchestight,facecolorwhite)# 矢量格式任意放大都不会模糊fig.savefig(pareto_different_alphas.svg,bbox_inchestight,facecolorwhite)fig.savefig(pareto_different_alphas.pdf,bbox_inchestight,facecolorwhite)plt.show()