国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

利用python繪制正態分布曲線

瀏覽:2日期:2022-06-30 13:24:28

使用Python繪制正態分布曲線,借助matplotlib繪圖工具;

利用python繪制正態分布曲線

#-*-coding:utf-8-*-'''python繪制標準正態分布曲線'''# ==============================================================import numpy as npimport mathimport matplotlib.pyplot as pltdef gd(x, mu=0, sigma=1): '''根據公式,由自變量x計算因變量的值 Argument: x: array 輸入數據(自變量) mu: float 均值 sigma: float 方差 ''' left = 1 / (np.sqrt(2 * math.pi) * np.sqrt(sigma)) right = np.exp(-(x - mu)**2 / (2 * sigma)) return left * rightif __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’) # 設置坐標系 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繪制正態分布曲線的詳細內容,更多關于python 正態分布的資料請關注好吧啦網其它相關文章!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 蒙山县| 商丘市| 尉氏县| 中牟县| 宣恩县| 安岳县| 台山市| 保定市| 陆丰市| 左贡县| 两当县| 顺平县| 克拉玛依市| 合川市| 永春县| 融水| 望奎县| 博爱县| 色达县| 虹口区| 安庆市| 渝中区| 徐水县| 新晃| 武安市| 太仓市| 驻马店市| 新巴尔虎左旗| 来宾市| 太仓市| 汉阴县| 缙云县| 斗六市| 政和县| 安塞县| 张掖市| 定边县| 河北省| 淮北市| 永城市| 霍州市|