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/9ec37da2f63388d2e9c792bde5b13713cc16897263255d5c9096407d87180f5e.png
h = hist(x)
xlabel('bins of x')
ylabel('frequency of x')
Text(0, 0.5, 'frequency of x')
../_images/5d8725515b31f5e8108267d0e78265b95b5f9aff0bffe17b710d88eff8f093c7.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/dc15b4c34f783919887d3100e9c970cc5bf7910d557ac8b0f4252a85c09b8f3f.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/1657b92cc574aad00ff70621acb03f2c5ed5bd1bf34cfe419e6a8e27779ba6ff.png
dx = diff(pos)[0]
print(('{:.2f}'.format(dx)))
1.52
density = probability/dx
bar(pos,density,width=1.4)
xlabel('bins of x')
ylabel('probability density')
Text(0, 0.5, 'probability density')
../_images/69556bfcf7d2361b17407ff04fc359607a1e83440d3085dc6076b32e74e1337f.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/ec9cde6dc2b8157d36e7792f773cf581dab1fb6153a3fb264cfaff55cea9e3ca.png