# -*- coding:utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt

# ----- 条件設定 -----
mu, sigma = 2.0, 2.0
N = 10000                # サンプル数
Nb = 100                 # ヒストグラムプロットのビン数
min_x, max_x = mu-5*sigma, mu+5*sigma
dx = (max_x-min_x)/Nb    # ビン幅


# ----- 正規分布乱数の生成と統計 -----
s = np.random.normal(mu, sigma, N)
av  = np.mean(s)
std = np.std(s)


# ----- プロット作成 -----
x = np.linspace(min_x, max_x, 256)
y =  1/(sigma*np.sqrt(2*np.pi))*np.exp(-(x-mu)**2/(2*sigma**2))

plt.rcParams["font.size"] = 18
fig    = plt.figure()
plot_1 = fig.add_subplot(1,1,1)
plot_1.set_xlim([min_x, max_x])
plot_1.text(0.1, 0.8, "$\mu$: {0:.3f}\n$\sigma$: {1:.3f}".\
            format(av, std), transform=plot_1.transAxes,\
            color='b')
plot_1.hist(s, Nb, range=(min_x, max_x))
plot_1.plot(x, N*dx*y, 'r-', linewidth=2)

plt.show()
fig.savefig('normal_dist.pdf', orientation='portrait', \
            transparent=False, bbox_inches=None, frameon=None)
fig.clf()
