使用Python繪制三種概率曲線詳解
更新時間:2022年03月23日 09:38:54 作者:hhh江月
這篇文章主要為大家分享了如何利用Python實現(xiàn)概率曲線的繪制,文中繪制了正態(tài)分布的曲線和指數(shù)分布的曲線,感興趣的可以了解一下
曲線一
解釋
這里是使用matplotlib來繪制正態(tài)分布的曲線。
代碼實現(xiàn)
import numpy as np
import matplotlib.pyplot as plt
def test1(n, m=500):
out = []
result = np.random.normal(1, 5, n * m)
print(result)
for i in range(m):
average0 = 0
for j in range(n):
average0 += result[n * i + j]
if j == n - 1:
out.append(average0 / n)
average0 = 0
print(out)
plt.hist(out,bins=25)
plt.title("test (1)")
plt.xlabel("x")
plt.ylabel("rate")
plt.show()
test1(5)曲線二
解釋
這里使用了matplotlib.pyplot來實現(xiàn)指數(shù)分布的繪制,具體的代碼實現(xiàn)參見下面所示:
代碼實現(xiàn)
import numpy as np
import matplotlib.pyplot as plt
def test2(n, m=500):
out0 = []
result0 = np.random.exponential(scale=1, size=n * m)
# print(result0)
for i in range(m):
average000 = 0
for j in range(n):
average000 += result0[n * i + j]
if j == n - 1:
out0.append(average000 / n)
average000 = 0
# print(out0)
plt.hist(out0,bins=25)
plt.show()
test2(5)曲線三
代碼實現(xiàn)
import numpy as np
import matplotlib.pyplot as plt
def test3(n1, m111=500):
out11 = []
# np.random.standard_t
result11 = np.random.standard_t(1, size=n1 * m111)
# print(result)
for i in range(m111):
average0 = 0
for j in range(n):
average0 += result11[n1 * i + j]
if j == n - 1:
out11.append(average0 / n1)
average0 = 0
# print(out11)
plt.hist(out11,bins=20)
plt.title("test (3)")
plt.show()
test3(30)到此這篇關(guān)于使用Python繪制三種概率曲線詳解的文章就介紹到這了,更多相關(guān)Python概率曲線內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
pymysql 插入數(shù)據(jù) 轉(zhuǎn)義處理方式
今天小編就為大家分享一篇pymysql 插入數(shù)據(jù) 轉(zhuǎn)義處理方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03
Python使用POP3和SMTP協(xié)議收發(fā)郵件的示例代碼
這篇文章主要介紹了Python使用POP3和SMTP協(xié)議收發(fā)郵件的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04
django自定義非主鍵自增字段類型詳解(auto increment field)
這篇文章主要介紹了django自定義非主鍵自增字段類型詳解(auto increment field),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03

