📜  如何在Python中创建泊松概率质量函数图?

📅  最后修改于: 2022-05-13 01:54:22.646000             🧑  作者: Mango

如何在Python中创建泊松概率质量函数图?

在本文中,我们将看到如何在Python中创建泊松概率质量函数图。在概率论和统计学中,泊松分布是一种离散概率分布,它表示给定数量的事件在固定的时间或空间间隔内发生的概率,如果这些事件以已知的恒定平均速率发生并且与自事件发生以来的时间无关。最后一次活动。泊松分布也可用于其他指定区间(例如距离、面积或体积)中的事件数。

为了绘制泊松分布,我们将使用 scipy 模块。 SciPy是一个免费的开源Python库,用于科学计算和技术计算。 SciPy 包含用于优化、线性代数、积分、插值、特殊函数、FFT、信号和图像处理、ODE 求解器和其他科学和工程中常见任务的模块。

示例 1:

Python3
# importing poisson fro scipy
from scipy.stats import poisson
 
# importing numpy as np
import numpy as np
 
# importing matplotlib as plt
import matplotlib.pyplot as plt
 
 
# creating a numpy array for x-axis
x = np.arange(0, 100, 0.5)
 
# poisson distribution data for y-axis
y = poisson.pmf(x, mu=40, loc=10)
 
 
# plotting the graph
plt.plot(x, y)
 
# showing the graph
plt.show()


Python3
# importing poisson fro scipy
from scipy.stats import poisson
 
# importing numpy as np
import numpy as np
 
# importing matplotlib as plt
import matplotlib.pyplot as plt
 
 
# creating a numpy array for x-axis
# using step size as 1
x = np.arange(0, 100, 1)
 
# poisson distribution data for y-axis
y = poisson.pmf(x, mu=10, loc=40)
 
 
# plotting the graph
plt.plot(x, y)
 
# showing the graph
plt.show()


Python3
# importing poisson fro scipy
from scipy.stats import poisson
 
# importing numpy as np
import numpy as np
 
# importing matplotlib as plt
import matplotlib.pyplot as plt
 
 
# creating a numpy array for x-axis
x = np.arange(0, 100, 0.5)
 
# poisson distribution data for y-axis
y = poisson.pmf(x, mu=50, loc=0)
 
 
# plotting thescatter plot graph
plt.scatter(x, y)
 
# showing the graph
plt.show()


输出 :

示例 2:使用数据的步长为 1

蟒蛇3

# importing poisson fro scipy
from scipy.stats import poisson
 
# importing numpy as np
import numpy as np
 
# importing matplotlib as plt
import matplotlib.pyplot as plt
 
 
# creating a numpy array for x-axis
# using step size as 1
x = np.arange(0, 100, 1)
 
# poisson distribution data for y-axis
y = poisson.pmf(x, mu=10, loc=40)
 
 
# plotting the graph
plt.plot(x, y)
 
# showing the graph
plt.show()

输出:

示例 3:绘制散点图以更好地查看数据点

蟒蛇3

# importing poisson fro scipy
from scipy.stats import poisson
 
# importing numpy as np
import numpy as np
 
# importing matplotlib as plt
import matplotlib.pyplot as plt
 
 
# creating a numpy array for x-axis
x = np.arange(0, 100, 0.5)
 
# poisson distribution data for y-axis
y = poisson.pmf(x, mu=50, loc=0)
 
 
# plotting thescatter plot graph
plt.scatter(x, y)
 
# showing the graph
plt.show()

输出: