import numpy as np
import matplotlib.pyplot as plt
mu=float(input("請輸入算術平均數:"))
sigma=float(input("請輸入標準差:"))
x=np.linspace(-3,3,1000)
y=(np.exp(-((np.log(x)-mu)**2.)/2./sigma/sigma))/x/sigma/((2.*np.pi)**0.5)
yy=(np.exp(-((x-mu)**2.)/2./sigma/sigma))/sigma/((2.*np.pi)**0.5)
#繪圖
fig=plt.figure()
ax=fig.add_subplot(111)
#ax.scatter(x,yn,color='yellow')
plt.title('Normal and Lognormal pdf Graph', fontsize=18)
ax.plot(x,y,'blue')
plt.plot(x,y,label="Lognormal",color="blue",linewidth=2)
ax.plot(x,yy,'red')
plt.plot(x,yy,label="Normal",color="red",linewidth=2)
plt.legend()
plt.show()
mu=0 and sigma=1
沒有留言:
張貼留言