# 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[91][#],
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[91][#], 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[91] /@ 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 ! Oct 20 '16 at 15:27