import numpy as np
import matplotlib.pyplot as plt
from plotstyle import *

# normal distribution:
rng = np.random.RandomState(6281)
x = np.arange(-4.0, 4.0, 0.01)
g = np.exp(-0.5*x*x)/np.sqrt(2.0*np.pi)
r = rng.randn(100)

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=cm_size(figure_width, 1.1*figure_height))
ax1.set_xlabel('x')
ax1.set_xlim(-3.2, 3.2)
ax1.set_xticks(np.arange(-3.0, 3.1, 1.0))
ax1.set_ylabel('Frequency')
ax1.set_yticks(np.arange(0.0, 41.0, 10.0))
ax1.hist(r, 5, zorder=-10, **fsB)
ax1.hist(r, 20, zorder=-5, **fsC)

ax2.set_xlabel('x')
ax2.set_xlim(-3.2, 3.2)
ax2.set_xticks(np.arange(-3.0, 3.1, 1.0))
ax2.set_ylabel('Probab. density p(x)')
ax2.set_ylim(0.0, 0.44)
ax2.set_yticks(np.arange(0.0, 0.41, 0.1))
ax2.plot(x, g, zorder=-1, **lsA)
if mpl_major > 1:
    ax2.hist(r, 5, density=True, zorder=-10, **fsB)
    ax2.hist(r, 20, density=True, zorder=-5, **fsC)
else:
    ax2.hist(r, 5, normed=True, zorder=-10, **fsB)
    ax2.hist(r, 20, normed=True, zorder=-5, **fsC)

fig.savefig('pdfhistogram.pdf')