# Plot multiple curves on the same graph (Color and PlotLegends) [duplicate]

myfun[j_, mu_, sigma_] :=
With[{kdata = 5},
PDF[BinomialDistribution[kdata, 1/(1 + Exp[-x])], j]*
PDF[NormalDistribution[mu, sigma], x]
]

Plot[Table[myfun[j, -4, 9], {j, 0, 5}], {x, -10, 10}, PlotLegends -> Automatic]


Why does this not have different color? I would expect curves with different colors and some "Automatic" legends?

The example here works fine:

Plot[{Sin[x], Cos[x]}, {x, 0, 2 \[Pi]}, PlotLegends -> Automatic] I would think that Table[] creates a {} structure, just like the {Sin[x], Cos[x]}. So why not have color??

After changing to this:

tmp = Table[myfun[j, -4, 9], {j, 0, 5}]
Plot[tmp, {x, -10, 10}, PlotLegends -> Automatic] Now they have color, but the "unwanted" PlotLegends.

Is there a better way? Or an explanation?

I want to have the expressions as legends as well as color.

• I have marked this as a duplicate. Please review that Q&A (linked at the top) and afterward if you feel it does not answer your question please edit yours to focus specifically on the aspect that is different. – Mr.Wizard Jan 23 '15 at 0:26

## 1 Answer

myfun[j_, mu_, sigma_] :=
With[{kdata = 5},
PDF[BinomialDistribution[kdata, 1/(1 + Exp[-x])], j]*
PDF[NormalDistribution[mu, sigma], x]]


Plot has attribute HoldAll so the Table is initially a single object which is then plotted. Use Evaluate.

Attributes[Plot]


{HoldAll, Protected, ReadProtected}

Plot[
Evaluate[
Table[myfun[j, -4, 9], {j, 0, 5}]],
{x, -10, 10},
PlotLegends -> Automatic] 