# Legend color lines not visible

I try to plot several curves on one plot with legends, but the colors assigned to each curve are not showing in the legends.

Plot[
u + (1 - u)*(1/Pi*ArcTan[# (u - 1)] + 1/2) -
(u + 1)*(1/Pi*ArcTan[-# (u + 1)] + 1/2),
{u, -3, 3},
PlotRange -> 1.3, PlotStyle -> ColorData[#],
PlotLegends -> ToString[#]] & /@ {1, 2, 3, 10} // Show The line in the legend does not appear for a single curve

Plot[Sin[x], {x, 0, 2 Pi}, PlotLegends -> "1"] so the Map and Show construction will not display the lines either. To get those lines, you can wrap the value of the PlotLegends option in a List. For the above example, this yields

Plot[Sin[x], {x, 0, 2 Pi}, PlotLegends -> {"1"}] Plot[u + (1 - u)*(1/Pi*ArcTan[# (u - 1)] + 1/2) - (u + 1)*(1/Pi*ArcTan[-# (u + 1)] + 1/2),
{u, -3, 3},
PlotRange -> 1.3, PlotStyle -> ColorData[#], PlotLegends -> {ToString[#]}
] & /@ {1, 2, 3, 10} // Show Another approach that uses only one call to Plot could be:

val = {1, 2, 3, 10};
Plot[
Evaluate[(u + (1 - u)*(1/Pi*ArcTan[# (u - 1)] + 1/2) -
(u + 1)*(1/Pi*ArcTan[-# (u + 1)] + 1/2)) & /@ val
], {u, -3, 3},
PlotRange -> 1.3, PlotStyle -> ColorData /@ val, PlotLegends -> ToString /@ val
] The vertical spacings of the legends differ from those of the previous plot.

• Perfect !! Thanks a lot for your very clear answer and your additional information for Plot ! – henry Oct 20 '16 at 15:27
• Glad this was helpful :) – user31159 Oct 20 '16 at 15:30
• @DoHe to be clear, PlotLegends accepts arbitrary expressions, so that when you pass in "1" it is displaying the expression you enter which is displayed according to its formatting rules. Wrapping it in a List triggers the more extensive legend processing, and it is why you get the line then. – rcollyer Oct 20 '16 at 16:06