2
$\begingroup$

This question already has an answer here:

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.

$\endgroup$

marked as duplicate by Mr.Wizard Jan 23 '15 at 0:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ 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. $\endgroup$ – Mr.Wizard Jan 23 '15 at 0:26
2
$\begingroup$
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

$\endgroup$

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