Illustrating uniform distributions


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

%matplotlib inline

In [2]:
z = np.array([-1.1, 0.3, 1.5])
pz = np.ones(3)/3

In [3]:
x = np.arange(1.3, 1.7, 0.01)
px = (1/(1.7-1.3)) * np.ones(len(x))

In [4]:
px


Out[4]:
array([ 2.5,  2.5,  2.5,  2.5,  2.5,  2.5,  2.5,  2.5,  2.5,  2.5,  2.5,
        2.5,  2.5,  2.5,  2.5,  2.5,  2.5,  2.5,  2.5,  2.5,  2.5,  2.5,
        2.5,  2.5,  2.5,  2.5,  2.5,  2.5,  2.5,  2.5,  2.5,  2.5,  2.5,
        2.5,  2.5,  2.5,  2.5,  2.5,  2.5,  2.5])

In [5]:
fig = plt.figure(figsize=(17,8))
ax1 = fig.add_subplot(121)
ax1.plot(z, pz, 'ro')
for pt in zip(z, pz):
    ax1.plot([pt[0], pt[0]], [0, pt[1]], 'b--')
ax1.set_xlim([-1.5,2])
ax1.set_ylim([0,3])

ax2 = fig.add_subplot(122)
ax2.plot(x, px, 'r-')
ax2.plot([1.3, 1.3], [0, 2.5], 'b--')
ax2.plot([1.7, 1.7], [0, 2.5], 'b--')
ax2.set_xlim([-1.5,2])
ax2.set_ylim([0,3])


Out[5]:
(0, 3)

In [6]:
fig.savefig('uniform_distribution.pdf')

In [ ]: