In [15]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import poisson
In [40]:
def plot(n=1000,normalize=False):
    """Plot variance vs mean"""
    means = np.empty(n)
    variances = np.empty(n)
    for i in range(n):
        x = poisson.rvs(i+1,size=100)
        if normalize:
            x_max = x.max()
            x_min = x.min()
            x = 255*(x-x_min)/(x_max-x_min)
        means[i] = x.mean()
        variances[i] = x.var()
    plt.scatter(means,variances)
In [41]:
plot(normalize=False)
In [42]:
plot(normalize=True)
In [37]:
def plot2(n=100,normalize=False):
    """Plot variance vs mean"""
    means = np.empty(n)
    cvs = np.empty(n)
    for i in range(n):
        x = poisson.rvs(i+1,size=100)
        if normalize:
            x_max = x.max()
            x_min = x.min()
            x = 255*(x-x_min)/(x_max-x_min)
        means[i] = x.mean()
        cvs[i] = x.std()/x.mean()
    plt.scatter(means,cvs)
In [38]:
plot2(normalize=False)
In [39]:
plot2(normalize=True)
In [34]:
def plot3(n=100,normalize=False):
    """Plot variance vs mean"""
    means = np.empty(n)
    stds = np.empty(n)
    for i in range(n):
        x = poisson.rvs(i+1,size=100)
        if normalize:
            x_max = x.max()
            x_min = x.min()
            x = 255*(x-x_min)/(x_max-x_min)
        means[i] = x.mean()
        stds[i] = x.std()
    plt.scatter(means,stds)
In [35]:
plot3(normalize=False)
In [36]:
plot3(normalize=True)