1

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?

Stitch
  • 4,205
  • 1
  • 12
  • 28

1 Answers1

7

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

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

Carl Woll
  • 130,679
  • 6
  • 243
  • 355