1
$\begingroup$

This is unrelated to my previous question, but is based on it. The following example works fine:

data1 = {{{1, 2}, Red}, {{2, 3}, Blue}};
ListPlot[
 List /@ data1[[;; , 1]], 
 PlotMarkers -> 
  Apply[Graphics[{#, Rectangle[]}, ImageSize -> 15] &, 
   List /@ data1[[;; , 2]], {1}]
 ]

If we replace it, however, with

ListPlot[
 List /@ data1[[;; , 1]], 
 PlotMarkers -> Graphics[{#, Rectangle[]}, ImageSize -> 15] & /@ data1[[;; , 2]]
 ]

It doesn't work -- colors are the same. This can be fixed using Evaluate

ListPlot[List /@ data1[[;; , 1]], 
 PlotMarkers -> 
  Evaluate@(Graphics[{#, Rectangle[]}, ImageSize -> 15] & /@ data1[[;; , 2]])
 ]

Now we can suspect that ListPlot has HoldAll attributes, so we everything that needs to be evaluated (and Map does) will be held. However, unlike Plot, ListPlot doesn't have the HoldAll attribute

Plot // Attributes
ListPlot // Attributes

{HoldAll, Protected, ReadProtected}

{Protected, ReadProtected}

So, what's happening here?

$\endgroup$
7
$\begingroup$

& has very low precedence, so you need to include parentheses, e.g.:

PlotMarkers -> (Graphics[{#, Rectangle[]}, ImageSize -> 15] &) /@ data1[[;; , 2]]

$\endgroup$
  • $\begingroup$ Wow! I didn't know this. Seems so subtle. So, Evaluate overrides this default precedence? $\endgroup$ – Stitch Jan 29 '17 at 1:16
  • $\begingroup$ The ( after your Evaluate does that. $\endgroup$ – Felix Jan 29 '17 at 2:22

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