Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

enter image description here

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?

share|improve this question
4  
PlotMarkers->Graphics[...] as in here –  Timothy Wofford Jul 29 at 14:58

3 Answers 3

up vote 14 down vote accepted

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}] 

enter image description here

share|improve this answer
    
PlotTheme looks powerful. Will try it as soon as Mathematica 10 is downloaded! –  su1 Jul 29 at 18:50
    
Warning: the built-in triangle plot markers are incorrectly implemented in v.10, see here. –  Alexey Popkov Jul 31 at 12:39
    
@AlexeyPopkov, have you reported this to WRI? –  RunnyKine Jul 31 at 15:44
    
No, I have not yet. Feel free to report with a ref. to this. I think we should consider this as a bug. –  Alexey Popkov Jul 31 at 16:29

\[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[]},
   PlotRangePadding -> 0,
   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}
]

enter image description here

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

enter image description here


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], 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
]

enter image description here

share|improve this answer
    
Thanks Öskå. :-) –  Mr.Wizard Jul 29 at 15:06
2  
@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. –  Mr.Wizard Jul 29 at 22:54
1  
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. –  Alexey Popkov Jul 31 at 12:23
1  
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. –  Alexey Popkov Jul 31 at 15:12
1  
@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. :-/ –  Mr.Wizard Jul 31 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}}]]

enter image description here

share|improve this answer
    
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. –  Alexey Popkov Jul 31 at 12:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.