import numpy as np
import matplotlib.pyplot as plt

# 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 )

plt.xkcd()

fig = plt.figure( figsize=(6,3) )
ax = fig.add_subplot( 1, 2, 1 )
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.yaxis.set_ticks_position('left')
ax.xaxis.set_ticks_position('bottom')
ax.set_xlabel( 'x' )
ax.set_xlim(-3.2, 3.2)
ax.set_xticks( np.arange( -3.0, 3.1, 1.0 ) )
ax.set_ylabel( 'Frequency' )
ax.set_yticks( np.arange( 0.0, 41.0, 10.0 ) )
ax.hist(r, 5, color='#CC0000')
ax.hist(r, 20, color='#FFCC00')

ax = fig.add_subplot( 1, 2, 2 )
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.yaxis.set_ticks_position('left')
ax.xaxis.set_ticks_position('bottom')
ax.set_xlabel( 'x' )
ax.set_xlim(-3.2, 3.2)
ax.set_xticks( np.arange( -3.0, 3.1, 1.0 ) )
ax.set_ylabel( 'Probab. density p(x)' )
ax.set_ylim(0.0, 0.44)
ax.set_yticks( np.arange( 0.0, 0.41, 0.1 ) )
ax.plot(x, g, '-b', lw=2, zorder=-1)
ax.hist(r, 5, normed=True, color='#CC0000', zorder=-10)
ax.hist(r, 20, normed=True, color='#FFCC00', zorder=-5)

plt.tight_layout()
fig.savefig( 'pdfhistogram.pdf' )
#plt.show()

