NOTE: In this notebook I use the stats
sub-module of scipy
for all statistics functions, including generation of random numbers. There are other modules with some overlapping functionality, e.g., the regular python random module, and the scipy.random
module, but I do not use them here. The stats
sub-module includes tools for a large number of distributions, it includes a large and growing set of statistical functions, and there is a unified class structure. (And namespace issues are minimized.) See https://docs.scipy.org/doc/scipy/reference/stats.html.
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
# M.L. modification of matplotlib defaults
# Changes can also be put in matplotlibrc file,
# or effected using mpl.rcParams[]
#plt.style.use('classic')
plt.rc('figure', figsize = (7, 4.5)) # Reduces overall size of figures
plt.rc('axes', labelsize=16, titlesize=14)
plt.rc('figure', autolayout = True) # Adjusts supblot params for new size
plt.figure()
n = np.linspace(0,60,61)
x = np.linspace(0,60,601)
p = stats.poisson.pmf(n,35)
g = stats.norm.pdf(x,35,np.sqrt(35))
plt.scatter(n, p, c='red', label='Poisson: $\\bar{x} = 35$')
plt.plot(x, g, label='Gaussian: $\\bar{x} = 35, \\sigma = \\sqrt{35}$')
plt.xlim(0,60)
plt.axhline(0)
plt.legend();
plt.xlabel('x');
plt.ylabel('pdf')
Text(0, 0.5, 'pdf')
version_information
is from J.R. Johansson (jrjohansson at gmail.com); see Introduction to scientific computing with Python . If not already installed on your machine, run pip install --upgrade version_information
from the terminal
%load_ext version_information
version_information numpy,scipy, matplotlib
Software | Version |
---|---|
Python | 3.11.5 64bit [MSC v.1916 64 bit (AMD64)] |
IPython | 8.15.0 |
OS | Windows 10 10.0.26100 SP0 |
numpy | 1.23.2 |
scipy | 1.11.1 |
matplotlib | 3.7.2 |
Sat Feb 08 14:28:04 2025 Eastern Standard Time |