Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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:

enter image description here

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!

share|improve this question
    
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 at 19:05

3 Answers 3

up vote 5 down vote accepted

Perhaps simplest:

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

With the following graph:

enter image description here

share|improve this answer

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.

Mathematica graphics

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.