如何生成多个高斯图? [英] How to generate multiple gaussian plots?

查看:69
本文介绍了如何生成多个高斯图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绘制多个具有相同均值和标准差的高斯图,这意味着当第一个图以 20 结束时,第二个图必须从 20 开始到 40 结束,峰值在 30

I am trying to plot multiple gaussian plots that'll have same mean and std dev, meaning that when the first plot ends at 20, the second plot must start from 20 and end at 40 with the peak being at 30

mu = 10
sigma = 2
n = 2
x = np.linspace(0,n*20,n*20)
for i in range(0,n):
    pdf = stats.norm.pdf(x, n*mu, sigma)
    plt.plot(x, pdf)

但这只给了我一个图作为图像

but this gives me just one plot as Image

我想生成的是:

所需的输出

有人可以告诉我我在做的错误吗?

Can someone please tell me the mistake that I am doing?

推荐答案

首先,您的两个高斯人的均值不同,因为一个高斯数为10,另一个高斯数为30.

First, your two gaussians do not have the same means, since one is at 10 and the other at 30.

第二,您实际上是在创建一个高斯,平均值为 n * mu = 20 .如果您需要生成多个高斯信号,则必须多次调用 norm.pdf ,例如循环:

Second, you are actually creating one one gaussian, with mean at n*mu=20. If you need to generate multiple gaussians, you'll have to call norm.pdf several times, e.g. in a loop:

mus = [10,30]
sigmas = [2,2]
x = np.linspace(0,40,100)
pdf = np.zeros(shape=x.shape)
for m,s in zip(mus,sigmas):
    pdf += stats.norm.pdf(x, m, s)
plt.plot(x, pdf)

这篇关于如何生成多个高斯图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆