今天就跟大家聊聊有關(guān)使用python怎么繪制一個(gè)正態(tài)分布曲線,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
使用Python繪制正態(tài)分布曲線,借助matplotlib繪圖工具;
#-*-coding:utf-8-*- """ python繪制標(biāo)準(zhǔn)正態(tài)分布曲線 """ # ============================================================== import numpy as np import math import matplotlib.pyplot as plt def gd(x, mu=0, sigma=1): """根據(jù)公式,由自變量x計(jì)算因變量的值 Argument: x: array 輸入數(shù)據(jù)(自變量) mu: float 均值 sigma: float 方差 """ left = 1 / (np.sqrt(2 * math.pi) * np.sqrt(sigma)) right = np.exp(-(x - mu)**2 / (2 * sigma)) return left * right if __name__ == '__main__': # 自變量 x = np.arange(-4, 5, 0.1) # 因變量(不同均值或方差) y_1 = gd(x, 0, 0.2) y_2 = gd(x, 0, 1.0) y_3 = gd(x, 0, 5.0) y_4 = gd(x, -2, 0.5) # 繪圖 plt.plot(x, y_1, color='green') plt.plot(x, y_2, color='blue') plt.plot(x, y_3, color='yellow') plt.plot(x, y_4, color='red') # 設(shè)置坐標(biāo)系 plt.xlim(-5.0, 5.0) plt.ylim(-0.2, 1) ax = plt.gca() ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.spines['bottom'].set_position(('data', 0)) ax.yaxis.set_ticks_position('left') ax.spines['left'].set_position(('data', 0)) plt.legend(labels=['$\mu = 0, \sigma^2=0.2$', '$\mu = 0, \sigma^2=1.0$', '$\mu = 0, \sigma^2=5.0$', '$\mu = -2, \sigma^2=0.5$']) plt.show()
看完上述內(nèi)容,你們對(duì)使用python怎么繪制一個(gè)正態(tài)分布曲線有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。
新聞標(biāo)題:使用python怎么繪制一個(gè)正態(tài)分布曲線-創(chuàng)新互聯(lián)
文章網(wǎng)址:http://aaarwkj.com/article48/dsjihp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、網(wǎng)站內(nèi)鏈、網(wǎng)站排名、云服務(wù)器、網(wǎng)頁(yè)設(shè)計(jì)公司、網(wǎng)站導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容