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$

closed as off-topic by Michael E2, C. E., m_goldberg, MarcoB, J. M. will be back soon Jan 29 '17 at 8:24

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Michael E2, C. E., m_goldberg, MarcoB, J. M. will be back soon
If this question can be reworded to fit the rules in the help center, please edit the question.

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.