# How to use the same colors in Epilog and Plot

How can you use the same colour to the data in Epilog as the data in the ListLinePlot?

I am plotting 25 lists (4 in this question) on which I would need to mark each maximum.

I would like the point marking the maximum to have the same colour as the line (if possible with a black exterior circle).

Is it possible?

a = {1, 3, 6, 3, 2};
b = {3, 2, 5, 6, 9};
c = {2, 7, 3, 1, 6};
d = {4, 2, 8, 8, 10};
am = {Position[a, Max[a]][[1, 1]], Max[a]}
bm = {Position[b, Max[b]][[1, 1]], Max[b]}
cm = {Position[c, Max[c]][[1, 1]], Max[c]}
dm = {Position[d, Max[d]][[1, 1]], Max[d]}
ListLinePlot[{a, b, c, d}, AxesLabel -> {"Iteraciones", "Objetivo"},
LabelStyle -> {24, Bold},
PlotStyle -> {{Thickness[0.01]}, {Thickness[0.01]}, {Thickness[
0.01]}}, Epilog -> {PointSize[0.04], Point[{am, bm, cm, dm}]}]
• The default colours are ColorData[1, n] for $n = 1, 2, \ldots$ – Rahul Apr 28 '14 at 9:41

First you define the colors with PlotStyle and then you draw the points twice in the Epilog - large in black and smaller in the same colors as the lines. Adapt the PlotRange in order to have the points not clipped.

cols = {Red, Green, Blue, Purple}

ListLinePlot[{a, b, c, d}, PlotStyle ->cols, AxesLabel -> {"Iteraciones", "Objetivo"},
LabelStyle -> {24, Bold}, PlotStyle -> {{Thickness[0.01]}, {Thickness[0.01]},
{Thickness[0.01]}}, Epilog -> {{PointSize[0.06], Point[{am, bm, cm, dm},
VertexColors -> {Black}]}, {PointSize[0.04], Point[{am, bm, cm, dm},
VertexColors -> cols]}}, PlotRange -> {{1, 5.5}, {1, 11}}, ImageSize -> 500]

• PERFECT. Only one question, I have series of 35-50 lineas and their maximuns. If I want use any "MAP"(I don´t know how to do.) or I want to use the default colors. How Can I use these colors(default.. but not black) TOO in the Epilog ( interior points... Blue, Purple, Yelloow, Green,... ciclelly) ? without typing ..using the default cicle of MAthematica use for lines... TOO in POINTS. – Mika Ike Apr 28 '14 at 9:30

For completeness purposes and thanks to the maxes function in kguler's answer, here is an example working for $n$ extrema.

a = {1, 3, 6, 3, 2};
b = {3, 2, 9, 6, 9};
c = {2, 7, 3, 1, 6};
d = {4, 2, 8, 8, 10};
varToPlot = {a, b, c, d};
maxes = Thread@Through[{Flatten[Position[#, Max[#]]] &, Max}[#]] & /@ varToPlot;
ListLinePlot[varToPlot, AxesLabel -> {"Iteraciones", "Objetivo"},
PlotStyle -> Thickness[0.01],
Epilog -> {EdgeForm[{Thick, Black}],
{ColorData[1, #],
Disk[#, {.1, 1/3}] & /@ maxes[[#]]} & /@ Range@Length@maxes},
ImageSize -> 500, PlotRange -> {{1, 5.5}, {1, 11}}]

• I like very much your answer (IS A PERFECT SOLUTION), but Kardasher answer first and Kardasher has less points. – Mika Ike Apr 28 '14 at 14:26

Alternative ways without Epilog:

lists = {a, b, c,  d} =
{{1, 3, 6, 3, 2}, {3, 2, 5, 6, 9}, {2, 7, 3, 1, 6, 7}, {4, 2, 8, 8, 10}};
(* note: the list c modified to have two maxima *)
len = Length@lists;
maxes = Thread@Through[{Flatten[Position[#, Max[#]]] &, Max}[#]] & /@lists;
colors = ColorData[3, "ColorList"] (* or your choice of colors*);

1. If you did not need the black edges, you could have simply used

ListPlot[Join[lists, maxes],
Joined -> ArrayPad[{True, False}, len - {1, 1}, "Fixed"],
PlotStyle -> Directive[Thick, PointSize[.04]]]

or

Show[ListLinePlot[lists, PlotStyle -> Thick],
ListPlot[maxes, PlotStyle -> Directive[Thick, PointSize[.04]]]]

For specific color lists of your choice (say colors):

ListPlot[Join[lists, maxes],
Joined -> ArrayPad[{True, False}, len - {1, 1}, "Fixed"],
PlotStyle -> (Directive[Thick, PointSize[.04], #] & /@colors[[;; len]])]

2. If you do need the black edges on the markers you can use PlotMarkers. Define a custom marker function using the tricks from this answer by @rm-rf

markerF := {Graphics[{EdgeForm[{Gray, Thick}],
Dynamic@FaceForm[CurrentValue["Color"]], Disk[{0, 0}, #]}], .07} &;

and use in a single ListPlot:

ListPlot[Join[lists, maxes],