3
$\begingroup$

I have a list of lists, for example:

list[1] = {{10, 20}, {400, 500}, {450, 602}, {580, 700}, {700, 
830}, {810, 920}}

 For[i = 2, i <= 4, i++,

  list[i] = list[1] + Table[{RandomReal[{-30, 30}], 0}, {i, 1, 6}]
    ]

And I ListPlot all of them together:

ListPlot[Table[list[i], {i, 1, 4}], PlotMarkers -> {Automatic, 100}, 
AspectRatio -> 1, ImageSize -> 500]

Listplot implements it's own coloring, giving every list a separate color. However, I want to color the first entries of every list a certain color, say red, the second entries green, the third blue and so on. Is there some kind of plotstyle option to do that within ListPlot? Thanks!

$\endgroup$
3
$\begingroup$

It seems quite a hack, but it works:

Needs["PolygonPlotMarkers`"]
markers[size_] := Block[{
    colors = {Red, Green, Blue, Orange, Purple, Pink},
    shapes = {"Disk", "Square", "Diamond", "UpTriangle"}}, 
   Flatten[Table[
     Graphics[{FaceForm[color], EdgeForm[], 
       PolygonMarker[shape, Offset[size]]}], {color, colors}, {shape, 
      shapes}]]];

ListPlot[Flatten[Table[{list[i][[j]]}, {j, 1, 6}, {i, 1, 4}], 1], 
 PlotMarkers -> markers[10], AspectRatio -> 1, ImageSize -> 500]

enter image description here

Note that in the definition of markers, colors has the same length as your individual lists and shapes the same length as the number of lists. You can certainly do this also with regular font-based markers, but then you can't rely on their positioning.

$\endgroup$
3
$\begingroup$
data = Table[list[i], {i, 1, 4}];
colors = {Red, Green, Blue, Orange, Cyan, Purple};

Restructuring input data

Transpose the input data, plot each part separately and combine with Show:

Show[ListPlot[List /@ #, PlotStyle -> #2, 
    PlotMarkers -> {Automatic, 10}, ImageSize -> 400] & @@@ 
  Transpose[{Transpose[data], colors}], PlotRange -> All]

Mathematica graphics

Post-Processing:

Post-process the original ListPlot output to re-color the markers:

ListPlot[data, PlotMarkers -> {Automatic, 10}, ImageSize -> 400] /. 
    {directives___, inset : __Inset} :> {directives, Transpose[{colors, {inset}}]}

Mathematica graphics

Alternatively, define a function for post-processing with user-provided colors:

postProcess[cl : (_Integer | _List) : 1] := Module[{col = 
     If[Head[cl] === Integer, ColorData[cl, "ColorList"], 
      cl]}, # /. {dir___, inset : __Inset} :> {dir, 
      Transpose[{col[[;; Length[{inset}]]], {inset}}]}] &

Examples:

plt = ListPlot[data, PlotMarkers -> {Automatic, 10}, ImageSize -> 400];

postProcess[colors] @ plt

Mathematica graphics

postProcess[] @ plt

Mathematica graphics

postProcess[3] @ plt

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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