This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/statistics/lecture/pdfhistogram.py

40 lines
1.0 KiB
Python

import numpy as np
import matplotlib.pyplot as plt
# normal distribution:
x = np.arange( -4.0, 4.0, 0.01 )
g = np.exp(-0.5*x*x)/np.sqrt(2.0*np.pi)
r = np.random.randn( 100 )
plt.xkcd()
fig = plt.figure( figsize=(6,4) )
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_ylabel( 'Frequency' )
#ax.set_ylim( 0.0, 0.46 )
#ax.set_yticks( np.arange( 0.0, 0.45, 0.1 ) )
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_ylabel( 'Probability density p(x)' )
#ax.set_ylim( 0.0, 0.46 )
#ax.set_yticks( np.arange( 0.0, 0.45, 0.1 ) )
ax.hist(r, 5, normed=True, color='#CC0000')
ax.hist(r, 20, normed=True, color='#FFCC00')
plt.tight_layout()
fig.savefig( 'pdfhistogram.pdf' )
plt.show()