12
$\begingroup$

In this plot the Disk[] markers are not colored according to the style of the line to which they belong:

SeedRandom[12]
data = Accumulate /@ RandomReal[3, {4, 10}] {1, 2, 3, 4};

ListLinePlot[data,
  PlotMarkers -> Graphics[Disk[], ImageSize -> 13],
  PlotLegends -> Automatic
]

enter image description here

Curiously, note that they are colored in the legend. How can I make the lines match the legend?

$\endgroup$
  • $\begingroup$ I didn't expect to see a bounty on this. Thank you, Szabolcs! $\endgroup$ – Mr.Wizard Jul 21 '15 at 19:01
16
+100
$\begingroup$

Though I was expecting to need something fancy I stumbled upon a simple solution:

ListLinePlot[data,
  PlotMarkers -> Graphics[{Disk[]}, ImageSize -> 13],
  PlotLegends -> Automatic
]

enter image description here

The only change is enclosing Disk[] in { }.

Looking at the InputForm we see that expressions involving Disk have been changed to e.g.:

Graphics[{
  Hue[0.67, 0.6, 0.6], Directive[PointSize[0.019444444444444445], 
  RGBColor[0.368417, 0.506779, 0.709798], AbsoluteThickness[1.6]], 
  Disk[{0, 0}]
}, ImageSize -> 13]

Apparently when a List appears as the first argument of Graphics the plot routine prepends the style information.

As far as I know this behavior is undocumented.

$\endgroup$
  • $\begingroup$ You used a degenerate case (single element, i.e., cycle of one) of the documented: "With PlotMarkers -> {Subscript[g, 1],[Ellipsis],Subscript[g, n]} the Subscript[g, i] are used cyclically for successive dataset lists." (from PlotMarkers documentation) However, using Automatic markers enables distinguishing the different lines even when seen in black and white. ListLinePlot[data, PlotMarkers -> {Automatic, 16}, PlotLegends -> Automatic] $\endgroup$ – Bob Hanlon Jul 31 '14 at 17:45
  • $\begingroup$ @BobHanlon I don't know if I understand your point but if I do I do not agree with it. I am using the form: "g markers consisting of copies of expression g" There is nothing "degenerate" about it that I can see. $\endgroup$ – Mr.Wizard Jul 31 '14 at 18:04
  • $\begingroup$ My interpretation is that the list you added inside of the Graphics constitutes the cycle list (length of one) used for the markers. But I could easily be wrong. $\endgroup$ – Bob Hanlon Jul 31 '14 at 18:23
  • 1
    $\begingroup$ @BobHanlon The same behavior is observed in non-degenerated cases (in your sense): ListLinePlot[data,PlotMarkers->{Graphics[Disk[],ImageSize->13],Graphics[Disk[],ImageSize->13]}]. So your interpretation is wrong. Personally I think it is just an ordinary example of gedanken functionality in Mathematica: the developer simply forgot to handle the case when the first argument of Graphics is not wrapped by List. $\endgroup$ – Alexey Popkov Jul 31 '14 at 18:53
  • 1
    $\begingroup$ not duplicate but related: mathematica.stackexchange.com/questions/5400/… $\endgroup$ – Mike Honeychurch Jul 31 '14 at 22:54

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.