Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

%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)
<Figure size 640x480 with 1 Axes>
h = hist(x)
xlabel('bins of x')
ylabel('frequency of x')
<Figure size 640x480 with 1 Axes>
# 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>
<Figure size 640x480 with 1 Axes>
# now we can normalize:
probability = frequency/sum(frequency)
bar(pos,probability,width=1.4)
xlabel('bins of x')
ylabel('probability')
<Figure size 640x480 with 1 Axes>
dx = diff(pos)[0]
print(('{:.2f}'.format(dx)))
1.40
density = probability/dx
bar(pos,density,width=1.4)
xlabel('bins of x')
ylabel('probability density')
<Figure size 640x480 with 1 Axes>
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);
<Figure size 640x480 with 1 Axes>