Contents

%pylab inline
%pylab is deprecated, use %matplotlib inline and import the required libraries.
Populating the interactive namespace from numpy and matplotlib
x = random.normal(10.0, 3.0,size=200)
plot(x)
xlabel('time',fontsize=16)
ylabel(r'$x$',fontsize=16)
Text(0, 0.5, '$x$')
../_images/bb229fc491280dc2eaeeb2225e17ed68fe43583b0a82cd912a494ddab60bc40c.png
h = hist(x)
xlabel('bins of x')
ylabel('frequency of x')
Text(0, 0.5, 'frequency of x')
../_images/5130db53e16a1d8dafd5d93c04e9dd1c1978a4f34444f65982af4c24ee802144.png
# make it yourself
pos = h[1][:-1]+diff(h[1])/2.
frequency = h[0]
bar(pos,frequency,width=1.4)
<BarContainer object of 10 artists>
../_images/fd156582bc43aeb5d7b6d9b6aeff71d23f090a44468110093ae29fd3a1dd2881.png
# now we can normalize:
probability = frequency/sum(frequency)
bar(pos,probability,width=1.4)
xlabel('bins of x')
ylabel('probability')
Text(0, 0.5, 'probability')
../_images/8e35b4ba1fb83a4d0001246b159d2d5ac3caf640547087a85c3ffc2d0a5524e2.png
dx = diff(pos)[0]
print(('{:.2f}'.format(dx)))
1.64
density = probability/dx
bar(pos,density,width=1.4)
xlabel('bins of x')
ylabel('probability density')
Text(0, 0.5, 'probability density')
../_images/eb8675258cb638f45af73878855b5545b36fbc9b8cb603ef448b9be5b16e860b.png
z = (pos - x.mean())/x.std()
# probability density function 
pdf = x.std() * density
from scipy.stats import norm

y = norm.pdf( z, 0, 1)
bar(z,pdf,alpha=.3,width=.4),
zi = arange(-3,3,.1)
yi = norm.pdf( zi, 0, 1)
plot(zi, yi, 'k--', linewidth=2)
xlabel(r'$z$',fontsize=16)
ylabel(r'pdf', fontsize=16);
../_images/b1553788b69ee8d66c6c138954e78b56d7a0c68cad91fdd7acc15acb077ff180.png