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_m=1.0alphas=[0.5,1.0,1.5,2.0,3.0,5.0,10.0]x=np.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, axes=plt.subplots(1,3,figsize=(21,7),constrained_layout=True)colors=plt.cm.viridis(np.linspace(0,0.95, len(alphas)))foralpha, colorinzip(alphas, colors): label=rf"$\alpha={alpha}$"axes[0].plot(x, pareto_pdf(x, x_m, alpha),color=color,label=label)axes[1].plot(x, pareto_cdf(x, x_m, alpha),color=color,label=label)axes[2].loglog(x, pareto_survival(x, x_m, alpha),color=color,label=label)# PDFaxes[0].set_xlim(x_m,10)axes[0].set_ylim(bottom=0)axes[0].set_xlabel(r"$x$")axes[0].set_ylabel(r"$f(x)$")axes[0].set_title("Probability density function")axes[0].grid(True,alpha=0.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,which="both",alpha=0.3)axes[1].legend()# Survival functionaxes[2].set_xlabel(r"$x$ (log scale)")axes[2].set_ylabel(r"$P(X>x)$ (log scale)")axes[2].set_title("Tail probability")axes[2].grid(True,which="both",alpha=0.3)axes[2].legend()fig.suptitle(rf"Pareto distributions with different $\alpha$,$x_m={x_m}$",fontsize=20)# 600 DPI高清PNGfig.savefig("pareto_different_alphas_600dpi.png",dpi=600,bbox_inches="tight",facecolor="white")# 矢量格式:任意放大都不会模糊fig.savefig("pareto_different_alphas.svg",bbox_inches="tight",facecolor="white")fig.savefig("pareto_different_alphas.pdf",bbox_inches="tight",facecolor="white")plt.show()
![]()