# How do I plot two Gaussians/normal distributions with 2 different means and 2 different standard deviations?

This is probably very easy for someone with more experience, but I am trying to plot only two Normal distributions, but for some reason my Method plots 4, instead of 2.

I have:

Plot[Evaluate@
Table[PDF[NormalDistribution[μ, σ], x],
{μ, 6, 7}, {σ, 1, 2}],
{x, 0, 12}, Filling -> Axis]


which plots:

My intention was to plot $Normal(\mu_1,\sigma_1)$ and $Normal(\mu_2,\sigma_2)$ instead of all the 4 possible combinations of them.

Thanks!

-
Instead of using Table, notice that MapThread[NormalDistribution, {{6, 7}, {1, 2}}] is equal to {NormalDistribution[6, 1], NormalDistribution[7, 2]}. So you can do Plot[{##}, {x, 0, 12}, Filling -> Axis] & @@ MapThread[Composition[PDF[#, x] &, NormalDistribution], {{6, 7}, {1, 2}}] – hftf May 4 '14 at 19:05

Perhaps simplest:

Plot[
{PDF[NormalDistribution[6, 1], x],
PDF[NormalDistribution[7, 2], x]},
{x, 0, 12}, Filling -> Axis]


With the following graph:

-

OR with less typing, especially when you have many such distributions:

Plot[PDF[NormalDistribution[##], x] & @@@ {{6, 1}, {7, 2}}, {x, 0, 12}, Filling -> Axis]


You can add Evaluated -> True as an Option if you want them in different colors.

-

It is not very surprising that this produces the four gaussians that it does, as you're using a square Table construction. If you want to keep an explicit Table command, you can use a more refined iterator, which you can find e.g. in the Table documentation.

Table[expr, {i, {i1, i2, ...}}]

uses the successive values i1, i2, ...

The naive try is then

Plot[Evaluate@
Table[PDF[NormalDistribution[pars], x],
{pars, { {6,1}, {7,2} } }],
{x, 0, 12}, Filling -> Axis]


though of course that won't work: it will call NormalDistribution[{6,1}] instead of NormalDistribution[6,1]. This has an easy fix using Apply (the @@):

Plot[Evaluate@
Table[PDF[NormalDistribution@@pars, x],
{pars, { {6,1}, {7,2} } }],
{x, 0, 12}, Filling -> Axis]


I think this solution is the least scary in terms of the number of weird symbols involved, while it also generalizes well to situations where you have many such plots and don't want to type the full PDF[NormalDistribution[]] throughout.

-