Python绘制高斯分布图像

文章目录

  • Python绘制高斯分布图像
    • 一、需求介绍
    • 二、第一个任务
    • 三、第二个任务
    • 四、readme文件

一、需求介绍

我们这里旨在使用Python来绘制图像,其他的操作一概先不管,绘制高斯分布的图像。

二、第一个任务

代码

import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import beta
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import math
import randomdef x_gauss(mu=0, sigma=1):"""x_gauss(you can change this method to make it can be input.):param mu: mu_x:param sigma: sigma_x:return: mu, sigma"""return mu, sigma# multiple variables.def y_gauss(mu=0, sigma=1):"""y_gauss(you can change this method to make it can be input.):param mu: mu_y:param sigma: sigma_y:return: mu, sigma"""return mu, sigma# multiple variables.def z_beta(alpha0=1, p0=1):"""z_beta(you can change this method to make it can be input.):param alpha0: alpha0:param p0: p0:return: alpha0, p0"""return alpha0, p0# p is a multiple variable, but alpha is not.if __name__ == '__main__':mu_x, sigma_x = x_gauss()mu_y, sigma_y = y_gauss()# get the mu and sigma parameter of the gauss.X = np.arange(mu_x - 5 * sigma_x, mu_x + 5 * sigma_x, 10 * sigma_x / 100)# range is related with sigma_x.Y = np.arange(mu_y - 5 * sigma_y, mu_y + 5 * sigma_y, 10 * sigma_y / 100)# range is related with sigma_y.# X and Y are arrays, ranging from mu - 5 * sigma to mu + 5 * sigma.X, Y = np.meshgrid(X, Y)# make meshgrided.alpha, p = z_beta()eta = beta.pdf(Y, alpha, p)  # Beta.# the equation of the eta.(eta ~ B(1, p))# however, as i need a range, so i use the range of Y.Z = \(1 / (pow(2 * math.pi, 1 / 2))) \* np.exp(- ((X - mu_x) ** 2) / (2 * (sigma_x ** 2))) \+ eta * \(1 / (pow(2 * math.pi, 1 / 2))) \* np.exp(- ((Y - mu_y) ** 2) / (2 * (sigma_y ** 2)))# Z = X + eta * Y.list_z = []# hist list.for line in Z:  # 100 lines.appending = random.choices(line, k=10)# 100 lines, 10 choices => 100 * 10 = 1000.for data in appending:list_z.append(data)"""two pictures => two windows.one is hist,the other is 3D."""# print(list_z, len(list_z))# 1000 points.plt.title('N~Z')# title.plt.xlabel('Z=X+η*Y')plt.ylabel('N')# labels.plt.hist(list_z)# draw the hist.fig = plt.figure()ax = Axes3D(fig)ax.plot_surface(X, Y, Z, rstride=1, cstride=1, alpha=0.5, cmap=cm.coolwarm)# draw the 3D function.plt.show()# show.

效果:

以及:

三、第二个任务

代码

import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import beta
import math
import randomdef x_gauss(mu=0, sigma=1):"""x_gauss(you can change this method to make it can be input.):param mu: mu_x:param sigma: sigma_x:return: mu, sigma"""return mu, sigma# multiple variables.def y_gauss(mu=0, sigma=1):"""y_gauss(you can change this method to make it can be input.):param mu: mu_y:param sigma: sigma_y:return: mu, sigma"""return mu, sigma# multiple variables.def z_beta(alpha0=1, p0=1):"""z_beta(you can change this method to make it can be input.):param alpha0: alpha0:param p0: p0:return: alpha0, p0"""return alpha0, p0# p is a multiple variable, but alpha is not.if __name__ == '__main__':"""n is a multiple variable."""n = 100# multiple variable.mu_x, sigma_x = x_gauss()mu_y, sigma_y = y_gauss()# get the mu and sigma parameter of the gauss.X = np.arange(mu_x - 5 * sigma_x, mu_x + 5 * sigma_x, 10 * sigma_x / 5000)# range is related with sigma_x.Y = np.arange(mu_y - 5 * sigma_y, mu_y + 5 * sigma_y, 10 * sigma_y / 5000)# range is related with sigma_y.# X and Y are arrays, ranging from mu - 5 * sigma to mu + 5 * sigma.X, Y = np.meshgrid(X, Y)# make meshgrided.alpha, p = z_beta()eta = beta.pdf(Y, alpha, p)  # Beta.# the equation of the eta.(eta ~ B(1, p))# however, as i need a range, so i use the range of Y.Z = \(1 / (pow(2 * math.pi, 1 / 2))) \* np.exp(- ((X - mu_x) ** 2) / (2 * (sigma_x ** 2))) \+ eta * \(1 / (pow(2 * math.pi, 1 / 2))) \* np.exp(- ((Y - mu_y) ** 2) / (2 * (sigma_y ** 2)))# Z = X + eta * Y.u = []# calculate the u.(1000)for i in range(1000):  # 1000.z_i = random.choices(Z[i], k=n)  # k = n.# n z.# calculate the u.u.append((1 / pow(n * np.var(z_i), 1 / 2)) * (sum(z_i) - n * np.mean(z_i)))# Ui = (1 / pow(n * np.var(z_i), 1 / 2)) * (sum(z_i) - n * np.mean(z_i))# 1000 u.plt.title('N~Ui')# title.plt.xlabel('Ui')plt.ylabel('N')# labels.plt.hist(u)# show the u.plt.show()# show

效果:

四、readme文件

This is the homework, there are two packages,
homework1 and homework2, homework1 is related
to work 1, and homework2 is related to work 2.There may be some modules that you do not have
in your environment, so maybe you should install
those modules first, such as, numpy, scipy,
matplotlib, mpl_toolkits and so on.After adding all the modules, you can change the
parameters like mu, sigma, p and so on, well,
you can also keep the parameters as you want,
and then,you can run the project and get the
results.In fact, homework2 is related to homework1,
but, in order to make the question more clear,
i divide the whole question into two small
questions, all in all, they are the same.

以上就是使用Python绘制高斯分布图像的一个案例啦,希望对大家有一些帮助啦,最后感谢大家的阅读与支持了啦。

Python绘制高斯分布图像相关推荐

  1. Python绘制高斯分布(正态分布)图像,附python绘图技巧

    高斯分布也称为正态分布,其概率密度函数如下: 使用Python绘制正态分布曲线,借助matplotlib绘图工具. 代码如下: # plot Gaussian Function # 注:正态分布也叫高 ...

  2. 用python绘制高光谱图像的光谱曲线图

    ENVI中绘制的光谱曲线图和可否用python绘制? 首先,答案是肯定的. 之前我绘制光谱曲线的的思路是用(x,y,:)取出高光谱图像中的某个像素处的数值作为纵坐标,光谱波段数作为横坐标(如1-31) ...

  3. python绘制函数图像opengl3d_写给 python 程序员的 OpenGL 教程

    原标题:写给 python 程序员的 OpenGL 教程 作者:牧马人 (本文来自作者投稿) 1预备知识 OpenGL 是 Open Graphics Library 的简写,意为"开放式图 ...

  4. python绘制三角函数图像

    利用matplotlib和numpy库绘制三角函数图像,包括正弦函数.余弦函数.正切函数.余切函数图像 代码如下: import numpy as np import matplotlib as mp ...

  5. Python遥感图像处理应用篇(二十四):Python绘制遥感图像各波段热力图(相关系数矩阵)

    给多光谱遥感图像各个波段绘制热力图,首先需要计算波段之间的相关系数矩阵,而计算遥感图像波段相关系数矩阵有不同的方法,常用的我们可以采用遥感图像处理软件计算,比如ENVI软件就可以计算相关系数矩阵,使用 ...

  6. Python绘制三维图像实例

    欢迎前往我的个人博客阅读原文. Python的Matplotlib库是一个比较强大的绘图库,可以比较好的代替Matlab实现绘图功能.下面我从学校开设的Matlab上机实验课程中的练习题挑出与绘图相关 ...

  7. python 图像字符绘制input描述_用python绘制函数图像

    有很多数学软件可以画函数图像,听说windows的计算器也有画函数图像的功能了.但是今天我们要用python来画一个正弦函数图像. 用到的第三方库:Matplotlib, Numpy 简单介绍下这两个 ...

  8. python绘制指数函数图像及性质_python实现画出e指数函数的图像

    这里用Python逼近函数y = exp(x);同样使用泰勒函数去逼近: exp(x) = 1 + x + (x)^2/(2!) + .. + (x)^n/(n!) + ... #!/usr/bin/ ...

  9. python绘制sinx图像_matplotlib.pyplot绘制图像之同一图中多条曲线对比

    绘制sinx和cosx # -*- coding:utf-8 -*- import numpy as np import matplotlib.pyplot as plt x = np.linspac ...

  10. python绘制指数函数图像及性质_指数函数图像及其性质正式版

    教学设计方案 课题名称: 指数函数图像及其性质 姓名: 安翠青 工作单 位: 滦 县 第 六 中 学 学科年级: 高一年级 教材版 本: 人教 A 版 一. 教学内容分析 指数函数是重要的基本初等函数 ...

最新文章

  1. log4j2的配置文件log4j2.xml笔记
  2. 关于 PHP 与 MYSQL的链接
  3. ShellExecuteA URLDownloadToFileA
  4. Linux不讲武德——开机无法进入登录界面 卡在进度条就不动了
  5. JSK-T1011 反向输出一个三位数【入门】
  6. 最小树形图(bzoj 4349: 最小树形图 2260: 商店购物)
  7. 第三季-第3课-Coredump程序故障分析
  8. [Java][Android] 多线程同步-主线程等待所有子线程完成案例
  9. 魔兽世界服务器文件,【魔兽世界7.35】魔兽一键安装服务端[带GM管理工具]
  10. 音视频系列--MediaProjection录屏生成H264和H265文件
  11. win10系统无法开启远程服务器配置,win10系统无法连接远程服务器的方案介绍...
  12. 解决ttf-mscorefonts-installer无法安装的问题
  13. 咕咕漫画之弹窗破解去除
  14. Java 性能优化实战工具实践:如何获取代码性能数据?
  15. 企业群发短信时为什么要找短信平台公司而不是直接找运营商发送
  16. 2012年奇虎360校园招聘实习生笔试编程题
  17. 【在线图表生成】掌握这些图表,年终报表根本不用愁!
  18. [转载] 晓说——第11期:揭秘我党历史上最危险的叛徒
  19. 【百科】萨布利亚·坦贝肯
  20. Retrofit流程及设计模式全解析

热门文章

  1. 操作系统之高速缓存区Cache替换算法
  2. 学网络营销毕业后能干什么
  3. 关于比特币的一些问题
  4. IP网络中的名字和地址
  5. Error: EPERM: operation not permitted, open ‘D:\Users\whh\Desktop\my-next-2\.next\trace‘
  6. 2021年1月16日sdut vj个人赛
  7. Python:28小黄人
  8. 2021腾讯笔试 - 计算抛物线与直线的面积
  9. 孩子,有些东西不属于你
  10. 汪洋长篇讲话推荐《大数据》