PlotLegends won't generate automatically more than 15 labels in v10
We may observe that the automatically generated legend limits the number of legend items to the number of available colors in the given color scheme. Using this utility function:
plot[scheme_] := Plot[Evaluate[Range[20] + x], {x, -5, 5},
PlotLegends -> "Expressions", PlotStyle -> scheme]
Observe the result for indexed color scheme #42 which has only four colors:
plot[42]
There are eight in #26:
plot[26]
As since there are 21 in #60 all your lines have a legend:
plot[60]
And if you specify a gradient color scheme:
Plot[Evaluate[Range[50] + x], {x, -5, 5}, PlotLegends -> "Expressions",
PlotStyle -> "Rainbow"]
You can use indexed colors as color function to generate as many distinct colors as you like. For example, although
Length @ ColorData[97, "ColorList"]
15
we can generate 100 distinct colors mapping ColorData[97]
on Range[100]
ColorData[97] /@ Range[100] // CountDistinct
100
ColorData[97, "Range"]
{1, ∞, 1}
ColorData[97, "ColorFunction"]
ColorData[97, "ColorFunction"] // InputForm
A nice illustration suggested by @Mr.Wizard in comments:
ArrayPlot[Partition[ColorData[97] /@ Range[500], 21],
Mesh -> All, MeshStyle -> White, ImageSize -> 1 -> 30]
So ... if we use PlotStyle -> (ColorData[97]/@Range[20])
the issue goes away:
Plot[Evaluate[Range[20] + x], {x, -5, 5},
PlotStyle -> (ColorData[97] /@ Range[20]),
PlotLegends -> "Expressions"]
and with PlotLegends -> Automatic
we get
Note that removing the PlotStyle
option or the setting PlotStyle -> 97
or PlotStyle -> ColorData[97]
we get only 15 distinct colors:
colorswithdefaultplotstyle = Cases[Plot[Evaluate[Range[20] + x], {x, -5, 5},
PlotLegends -> "Expressions"], {Directive[_, col_, ___],
_Line} :> col, All];
{Length @ #, CountDistinct @ #} & @ colorswithdefaultplotstyle
{20, 15}
This works for all 113 indexed colors.
$Version
11.3 .0 for Microsoft Windows (64 - bit) (March 7, 2018)