利用python繪制正態(tài)分布曲線
使用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()
以上就是利用python繪制正態(tài)分布曲線的詳細(xì)內(nèi)容,更多關(guān)于python 正態(tài)分布的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
基于Python Numpy的數(shù)組array和矩陣matrix詳解
下面小編就為大家分享一篇基于Python Numpy的數(shù)組array和矩陣matrix詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-04-04基于PyQt5實(shí)現(xiàn)SqlServer數(shù)據(jù)庫表導(dǎo)出Excel表格小工具
這篇文章主要為大家詳細(xì)介紹了PyQt5的應(yīng)用案例之實(shí)現(xiàn)SqlServer數(shù)據(jù)庫表導(dǎo)出Excel表格小工具,文中的示例代碼講解詳細(xì),需要的小伙伴可以參考一下2023-12-12python實(shí)戰(zhàn)之Scrapy框架爬蟲爬取微博熱搜
前面講解了Scrapy中各個模塊基本使用方法以及代理池、Cookies池。接下來我們以一個反爬比較強(qiáng)的網(wǎng)站新浪微博為例,來實(shí)現(xiàn)一下Scrapy的大規(guī)模爬取。2021-09-09Python如何存儲數(shù)據(jù)到j(luò)son文件
這篇文章主要介紹了Python如何存儲數(shù)據(jù)到j(luò)son文件,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-03-03python爬蟲開發(fā)之使用python爬蟲庫requests,urllib與今日頭條搜索功能爬取搜索內(nèi)容實(shí)例
這篇文章主要介紹了python爬蟲開發(fā)之使用python爬蟲庫requests,urllib與今日頭條搜索功能爬取搜索內(nèi)容實(shí)例,需要的朋友可以參考下2020-03-03Python使用正則匹配實(shí)現(xiàn)抓圖代碼分享
本文給大家分享的是個人的第一個作品,使用Python正則匹配實(shí)現(xiàn)抓圖代碼,非常的簡單實(shí)用,推薦給大家,小伙伴們可以自由擴(kuò)展下。2015-04-04Python pandas 列轉(zhuǎn)行操作詳解(類似hive中explode方法)
這篇文章主要介紹了Python pandas 列轉(zhuǎn)行操作詳解(類似hive中explode方法),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-05-05