%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/2112754ed7b0093e0608620d4feb37d6ea12a72d105e6c7e8e902997bc02844b.png
h = hist(x)
xlabel('bins of x')
ylabel('frequency of x')
Text(0, 0.5, 'frequency of x')
../_images/7175fc0cea4f3568372a6035292ee2677ef5d9a2f6aedfed8ffd7308291f0832.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/1827d278f5a1be884a68b512602321d72585dedc4c30730dfd2a0f9b481f6a0c.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/f171e23b449f45a7a18e50f8c0aeb6a3c77df7758c6ed430f52fe9cb2d297bdf.png
dx = diff(pos)[0]
print(('{:.2f}'.format(dx)))
1.76
density = probability/dx
bar(pos,density,width=1.4)
xlabel('bins of x')
ylabel('probability density')
Text(0, 0.5, 'probability density')
../_images/66bd42371e9a836d228dfd36605ff318e7b7e0ba8753562d0a7441216fa33ece.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/e9c683378c3fcdc675c61d6e4f76eb82146fb57f4870d84fb00052d4a5865f21.png