# Difference Colored legends from main plot

I am using the below code to create legends but I don't know why the colors in legends for various plots are different of devoted to main color of plots

From http://reference.wolfram.com/language/ref/Inset.html?q=Inset in Application part:

legendPlot[xl_List, d_, args___] :=
Plot[xl, d,
Epilog ->
Inset[Panel[
Grid[MapIndexed[{Graphics[{ColorData[1, First@#2], Thick,
Line[{{0, 0}, {1, 0}}]}, AspectRatio -> .5,
ImageSize -> 20], #1} &, xl]]],
Offset[{-2, -2}, Scaled[{1, 1}]], {Right, Top}], args]
legendPlot[{Cos[x], Sinc[x], Tan[x], Cot[x]}, {x, 0, 10}]


Sinc is Orange in the main plot Tan is Green, Cot is Red!!!! • What version are you using? That looks like Mathematica's newer default colors on the plot and the old default colors on the legend! Nov 29 '15 at 4:40
• Looks like the legendPlot is using older version for colors. The first workaround would be defining a new color code and using that color code at both plots. Nov 29 '15 at 4:47
• I am using version 10 both plot and legend!! Nov 29 '15 at 4:58

As an alternative implementation, consider

frame[legend_] := Framed[legend, FrameStyle -> Black, RoundingRadius -> 0,
FrameMargins -> 0, Background -> White];
legendPlot[xl_List, d_] := Plot[xl, d, PlotLegends -> Placed[LineLegend[
"Expressions", LabelStyle -> Italic, LegendFunction -> frame], {.88, .75}]];
legendPlot[{Cos[x], Sinc[x], Tan[x], Cot[x]}, {x, 0, 10}] To answer the specific question, the colors in the Plot and Epilog of the Question are different, because the colors used by Plot are not ColorData[1, ...]. Replace 1 by 97 for better agreement. The complete list of indexed colors can be displayed with

MatrixForm[Table[{i, ColorData[i, "ColorList"]}, {i, ColorData["Indexed"]}],
TableAlignments -> Left]


Adding in exclusions, just for interest.

plot = Plot[{Cos[x], Sinc[x], Tan[x], Cot[x]}, {x, 0, 10}];

colourpositions = Position[plot, _RGBColor, Infinity];

colours = Extract[plot, colourpositions];

tanplot = Plot[Tan[x], {x, 0, 10},
Exclusions -> Map[Pi #/2 &, 2 Range - 1],
PlotStyle -> colours[]];

cotplot = Plot[Cot[x], {x, 0, 10},
Exclusions -> Map[Pi #/2 &, 2 Range],
PlotStyle -> colours[]];

otherplots = Plot[{Cos[x], Sinc[x]}, {x, 0, 10}];

Show[otherplots, tanplot, cotplot,
PlotRange -> {Automatic, {-4, 4}}, 