When a list of PlotStyles is given, ListPlot behaves as expected when there are multiple things to plot:

ListPlot[{RandomReal[{-1, 1}, 100], 2 RandomReal[{-1, 1}, 100]}, PlotStyle -> {Red, Green, Blue}]

enter image description here

When there's only one thing to plot, it chooses the last PlotStyle instead of the first one.

ListPlot[RandomReal[{-1, 1}, 100], PlotStyle -> {Red, Green, Blue}]

enter image description here

Enclosing the single thing to be plotted in {} appears to cause things to behave as expected.

ListPlot[{RandomReal[{-1, 1}, 100]}, PlotStyle -> {Red, Green, Blue}]

enter image description here

Plot shows the same behavior.

This does not appear to happen with the default PlotStyles, but it does happen if you modify the default styles using this kind of technique.

Why is a single plot argument treated as a special case? Can this behavior be changed?


I would venture that when you have the lone function to plot, Mathematica assumes your list of styles should all be applied, and blue is just the one to be applied last. Consider for instance:

ListPlot[RandomReal[{-1, 1}, 100], PlotStyle -> {Red, PointSize[0.05], Blue}]

big blue points

What behavior would you expect or want to see instead?

Also consider this:

ListPlot[{RandomReal[{-1, 1}, 100]}, PlotStyle -> {{Red, Green, Blue}}]
  • $\begingroup$ Aha. I thought Directive was always required for multiple-word styles. This is a symptom of that not being the case. Thanks. $\endgroup$ – ArgentoSapiens May 9 '13 at 20:06
  • 1
    $\begingroup$ @ArgentoSapiens certainly using Directive is the correct, documented way to do it. Although the meaning of a list of directives without head Directive is rather ambiguous as you correctly point out in your question, I suppose some versions are more or less tolerant of such incorrect (but fairly commonly supplied) inputs than others. $\endgroup$ – Oleksandr R. May 11 '13 at 2:04

I have to wonder what version this is, since trying this on Mathematica 8 shows no difference.


dat = {-1, 0, 1/2, 2};

I see that

ListPlot[dat, PlotStyle -> {Red, Green, Blue}]


ListPlot[{dat}, PlotStyle -> {Red, Green, Blue}]

both produce the same plot, with blue points. Why this is the case might be a bit clearer if we peek into the InputForm[]:

ListPlot[dat, PlotStyle -> {Red, Green, Blue}] // InputForm
   Graphics[{{{}, {Hue[0.67, 0.6, 0.6],
             RGBColor[1, 0, 0], RGBColor[0, 1, 0], RGBColor[0, 0, 1],
             Point[{{1., -1.}, {2., 0.}, {3., 0.5}, {4., 2.}}]}, {}}},
            {AspectRatio -> GoldenRatio^(-1), Axes -> True, AxesOrigin -> {0, 0},
             PlotRange -> {{0, 4.}, {-1., 2.}}, PlotRangeClipping -> True,
             PlotRangePadding -> {Scaled[0.02], Scaled[0.02]}}]

where the bit most important for our purposes is {Hue[0.67, 0.6, 0.6], RGBColor[1, 0, 0], RGBColor[0, 1, 0], RGBColor[0, 0, 1], Point[{{1., -1.}, {2., 0.}, {3., 0.5}, {4., 2.}}]}. Notice the four, yes four color directives coming before the Point[] object. Doing something similar to ListPlot[dat, PlotStyle -> Blue] // InputForm gives the important part {Hue[0.67, 0.6, 0.6], RGBColor[0, 0, 1], Point[{{1., -1.}, {2., 0.}, {3., 0.5}, {4., 2.}}]}.

By now, you should realize why the behavior of making only the last directive apply to the primitive(s) ought to be the case; in the simpler case of ListPlot[dat, PlotStyle -> Blue], this allows you to see your points in the color you intended them to be (blue) instead of the default color used by ListPlot[]. In the OP's case, the other three colors preceding RGBColor[0, 0, 1] and the Point[] object are ignored in the final rendering, which is why you see them in blue.

In any event, if you're wondering why your third example turned red, you might want to inspect the InputForm[] and do a few comparisons.

  • 1
    $\begingroup$ Mine is version 9. It looks like they changed something. The green and blue colors never appear in the InputForm of the third example. $\endgroup$ – ArgentoSapiens May 10 '13 at 13:22
  • $\begingroup$ Huh, very interesting. Maybe you should update your question to include this observation. (Use a simpler set of points, tho!) $\endgroup$ – J. M.'s torpor May 10 '13 at 13:24

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.