import numpy as np import matplotlib.pyplot as plt a=np.loadtxt("data2.txt",dtype=float) nbins=100 xmax=a.max() xmin=a.min() mu=a.mean() sigma = a.std() textstr = '$\sigma=%.2f$'+str(round(sigma,2))+' $\mu=%.2f$'+str(round(mu,2)) x=np.linspace(0,xmax) y=(1/mu*np.exp(-1/mu*x)) fig,ax=plt.subplots() ax.plot(x,y,c="red") ax.hist(a,bins=nbins,density=True,histtype='step',range=[xmin,xmax]) props = dict(boxstyle='round', facecolor='wheat', alpha=0.5) ax.text(0.7, 0.95, textstr, transform=ax.transAxes, fontsize=8, verticalalignment='top', bbox=props) b=np.loadtxt("data1.txt",dtype=float) nbins=200 xmax=b.max() xmin=b.min() mu=b.mean() p=(2+1/mu) sigma = b.std() if p>3 or p<1 : textstr = '$\sigma=%.2f$'+str(round(sigma,2))+' $\mu=%.2f$'+str(round(mu,2)) elif 3>p>1 : textstr = '$\sigma=%.2f$'+'inf'+' $\mu=%.2f$'+str(round(mu,2)) x=np.linspace(0,20) y=((p+(-1))/(x+1)**p) fig,bx=plt.subplots() bx.plot(x,y,c="red") bx.hist(b,bins=nbins,density=True, histtype='step',range=[0,20]) props = dict(boxstyle='round', facecolor='wheat', alpha=0.5) bx.text(0.7, 0.95, textstr, transform=bx.transAxes, fontsize=8, verticalalignment='top', bbox=props) plt.show()