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/eb26118c68ceb49f9abbe321e088e15be3e6293eaf6bd7855cb8a0de4918fc95.png
h = hist(x)
xlabel('bins of x')
ylabel('frequency of x')
Text(0, 0.5, 'frequency of x')
../_images/464de954153f96958046c2600179095eb32344d121548c9a9a05f795fbf0e4e1.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/8887d4596d8e1b5c7a0084fca2c172708a227742c20326d64f08ae5efca8df1c.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/e2c15924a351b5ad45d364026981b2b01aeef3cdd761a9955637dff9939eeed1.png
dx = diff(pos)[0]
print(('{:.2f}'.format(dx)))
1.70
density = probability/dx
bar(pos,density,width=1.4)
xlabel('bins of x')
ylabel('probability density')
Text(0, 0.5, 'probability density')
../_images/64e6e0d5cfb38cb8b79143ddc1dfa9b098093169e345095cf0579239d05e2d3b.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/f0dea618047685cde3fa833ef5ead3a75e6fab4b26ca4f4fa6be5e05f1105a5d.png