In [2]:
import numpy as np
import matplotlib.pyplot as plt

x = np.arange(-1.,8.,0.01)
P = x*0.
for i in range(1,7,1):
    P[x>i]=i*1./6.
fig=figure();ax=fig.add_subplot(1,1,1)
ax.plot(x,P)
ax.set_xlabel('x - dice value');ax.set_ylabel('P(x)');ax.set_ylim([-0.1,1.1])
fig.savefig('images/DiceCDF.png')
In [4]:
# uniform 1,3
a=1.
b=3.
p = 0.*x
p[(x>a)&(x<b)]=1./(b-a)
P = np.cumsum(p)*np.median(np.diff(x))
In [9]:
fig=figure();ax=fig.add_subplot(2,1,1)
ax.plot(x,P)
ax.set_xlabel('x - Uniform');ax.set_ylabel('P(x)');ax.set_ylim([-0.1,1.1])
ax=fig.add_subplot(2,1,2)
ax.plot(x,p)
ax.set_xlabel('x - Uniform [1.,3.]');ax.set_ylabel('p(x)');ax.set_ylim([-0.1,1.1])
fig.savefig('images/UniformDist.png')
In [34]:
x = linspace(-10.,10.,1000.)
a=1.3
b=2.
p = (1./b/sqrt(2*np.pi))*exp(-(x-a)**2/2./b**2)
plot(x,p)
plot(array([1,1])*a,[0,0.3],'r--')
text(a,0.2,'  a',fontsize='large')
plot(array([1,1])*a+sqrt(2)*b,[0,0.3],'r--')
text(a+sqrt(2)*b,0.2,'  $a+\sqrt{2}b$',fontsize='large')
plot(array([1,1])*a-sqrt(2)*b,[0,0.3],'r--')
text(a-sqrt(2)*b,0.2,'  $a-\sqrt{2}b$',fontsize='large',horizontalalignment='right')
plot([-10,10],(1./b/sqrt(2*np.pi))*exp(-1)*array([1,1]),'r--')
text(a-sqrt(2)*b,(1./b/sqrt(2*np.pi))*exp(-1),r'  $\frac{1}{b\sqrt{2\pi}}e^{-1}$',fontsize='large',horizontalalignment='right')
xlabel('$x\ \  [V]$')
ylabel('$p(x)\ \ [V^{-1}]$')
title('Normal Distribution a=%1.2f, b=%1.2f'%(a,b))
savefig('images/NormalDist.png')
In [ ]: