2
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?

enter image description here

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]

enter image description here

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]

enter image description here

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.

VividD
  • 3,660
  • 4
  • 26
  • 42
Chen Stats Yu
  • 4,986
  • 2
  • 24
  • 50
  • 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 00:26

1 Answers1

2
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]

enter image description here

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198