# Change the inner color of markers

I would like to have a marker with white as its inner color, to be able to make this kind of graph:

If I use PlotMarkers -> Style["\[FilledSquare]", White], it changes both the inner color + border color but not the inner color only.

If I use PlotMarkers -> Style["\[EmptySquare]", White], the line of the curve goes above the marker.

How could I achieve that?

• PlotMarkers->Graphics[...] as in here Jul 29, 2014 at 14:58

In Version 10 you can use the PlotTheme "OpenMarkersThick":

data = Table[{x, x^k}, {k, 1, 4}, {x, 0, 1, 0.1}]

ListLinePlot[data, PlotTheme -> {"OpenMarkersThick", "LargeLabels"},
PlotLegends -> {x, x^2, x^3, x^4}]


• PlotTheme looks powerful. Will try it as soon as Mathematica 10 is downloaded! Jul 29, 2014 at 18:50

\[FilledSquare] is a font glyph and you cannot color parts of it.

I believe you need to draw your markers with Graphics primitives. For example:

square[in_, out_: Black, size_: 12] :=
Graphics[{in, EdgeForm[{AbsoluteThickness[2], out}], Rectangle[]},
ImageSize -> size]

data = {{1, 2, 3, 5, 8}, {2, 3, 6, 9, 10}, {4, 5, 7, 10, 12}};

ListLinePlot[data,
PlotMarkers -> square /@ {Red, Green, Blue}
]


ListLinePlot[data,
PlotMarkers -> square @@@ {{Yellow, Red}, {White, Blue}, {Black, Pink}}
]


Update: proof that this method can easily be used for markers of arbitrary shape.

Generic marker function:

marker[prim_, opts___][in_: White, out_: Black, size_: 13] :=
Graphics[{in, EdgeForm[{AbsoluteThickness[2], Opacity[1], out}], prim},
opts, ImageSize -> size]


Shapes:

square  = marker @ Rectangle[];
circle  = marker @ Disk[];
diamond = marker @ Polygon[{{0, 1}, {1, 2}, {2, 1}, {1, 0}}];
triangle =
marker[
Polygon[{{1, 0}, {0, Sqrt[3]}, {-1, 0}}],
AlignmentPoint -> {0, 1/Sqrt[3]}
];


Plot:

SeedRandom[12]

ListLinePlot[
Accumulate /@ RandomReal[3, {4, 10}] {1, 2, 3, 4},
PlotMarkers ->
{square[], circle[Yellow], diamond[Brown, Pink], triangle[Magenta, Purple]},
PlotLegends -> Automatic
]


• @Öskå Go ahead and edit. I'll probably refactor to make it more terse, as is my style, but I'm out of time now. See you later. :-) Jul 29, 2014 at 15:12
• @eldo You could use Primitives to produce any shape you like. Unlike other answers this one addresses the question in the Title: change the inner color of markers, not merely making centers white. (I wasn't aware of the theme "OpenMarkersThick" when I wrote this answer or surely would have included it.) I expect that chuy will earn the Accept but I don't think this is a bad answer. Jul 29, 2014 at 22:54
• Your implementation of the triangle plot markers is incorrect as well as @eldo's: the center of the triangle is located on 1/3 of its height, not 1/2 as in your implementation. See here. Jul 31, 2014 at 12:23
• Note that plot markers are aligned according to the AlignmentPoint option of Graphics. So if you add into your current triangle specification AlignmentPoint -> {0, 1/Sqrt[3]} you will get correct placement of the triangles. This value can be found via RegionCentroid@Polygon[{{1, 0}, {0, Sqrt[3]}, {-1, 0}}]. Of course for the other shapes in your answer this option should be different. Jul 31, 2014 at 15:12
• @Alexey That is not what my code is doing. (Or at least not what I intend.) I changed the definition to marker[prim_, opts___] to pass options to Graphics. Sorry to disappoint. :-/ Jul 31, 2014 at 16:33

You could build your own PlotMarkers

ngon[p_, q_] :=
Polygon[Table[{Cos[2 Pi k q/p], Sin[2 Pi k q/p]}, {k, p}]]

g1 = Graphics[{EdgeForm[Black], White, Disk[{0, 0}, 1]}];
g2 = Graphics[{EdgeForm[Black], White, Rectangle[{1, 1}]}];
g3 = Graphics[{EdgeForm[Black], White, ngon[4, 1]}];
g4 = Graphics[{EdgeForm[Black], White, Polygon[{{1, 0}, {0, Sqrt[3]}, {-1, 0}}]}];

ListLinePlot[Table[n^(1/p), {p, 4}, {n, 10}],
Filling -> Axis,
PlotLegends -> Automatic,
PlotMarkers -> Table[{s, 0.05}, {s, {g1, g2, g3, g4}}]]


• Note that the triangle plot markers are placed incorrectly in this answer: the center of the triangle is located on 1/3 of its height, not 1/2. See here. Jul 31, 2014 at 12:36

## ChartElementData["EmptyMarkers"]

ListLinePlot[4 Range[6] + RandomReal[{-1, 1}, {6, 20}],
Filling -> Thread[Range[5] -> List /@ Range[2, 6]],
PlotLegends -> Automatic]


To get thicker edges, use

PlotMarkers -> Thread[{ChartElementData["EmptyMarkers"][[All, 1]] /.
Thickness[_] :> AbsoluteThickness[3], .05}]


• Note that the triangle markers with this approach will be positioned incorrectly: try ListLinePlot[Table[{i,j},{i,6},{j,6}],PlotMarkers->Thread[{ChartElementData["EmptyMarkers"][[All,1]],.1}],GridLines->{None,All}]/.p_Polygon:>{Blue,PointSize[.15],Point[RegionCentroid[p]]} to see this. Detailed explanations are here. Jan 16, 2018 at 6:58
• @AlexeyPopkov, you are right. It is easier to see that the triangle marker is not centered at {.5, .5} is to evaluate ChartElementData["EmptyMarkers"][[4, 1]] /. Opacity[0] -> Opacity[.5] // Show[#, Frame -> True, GridLines -> {{.5}, {.5}}, GridLinesStyle -> Red, Method -> {"GridLinesInFront" -> True}] &
– kglr
Jan 16, 2018 at 7:16
• Actually as I explain here the triangle should NOT be centered at {.5, .5}, but at RegionCentro‌​id at {.5, 1/3} (for the upper triangle). Jan 16, 2018 at 7:20
• @Alexey, yes,;actually I meant to say it is centered at {.5,.5} .
– kglr
Jan 16, 2018 at 7:27