Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In the following query, If the option PlotStyle->{Red,Blue} is inserted it works but FillingStyle->{Red,Blue} does not: The filling turns all Blue. Is this a known issue? I tried basic ColorFunction but could only get rainbows. Any other options? It's desirable to alternate the segments using only 2 colors (though not Red and Blue, that's just for example).

Labeled[DateListPlot[#, Joined -> True, ImageSize -> 1000, 
    AspectRatio -> 1/5, 
    Epilog -> {Inset[
       Text[Style[">statigrafix<", Blue, Opacity[0.1], 
         FontFamily -> "Consolas", FontSize -> 14]], 
       Scaled[{0.15, 0.75}]]}, Frame -> {True, True, False, False}, 
    Filling -> Bottom, GridLines -> None] &@
  Split[FinancialData["^DJI", "Close", "Jan 1 1980"], 
   Not@(#[[2]] > 10000 && #2[[2]] <= 10000) &],
 Style["Dow Jones Industial 1.1.80-6.22.12 segmented by 10k \
crossings", Gray, Opacity[0.3], FontFamily -> "Helvetica"], Bottom]
share|improve this question
Can you attach a pic of what you are seeing? – Mike Honeychurch Jun 26 '12 at 2:49
Sure, what's the procedure for uploading a .png? – alancalvitti Jun 26 '12 at 2:51
Tried setting the options as Filling -> Axis, FillingStyle -> {1 -> Red, 2 -> Blue}, , ColorFunctionScaling->False? – kglr Jun 26 '12 at 3:04
@kguler, just tried it: as is, it only colors the first two segments in Red and Blue, while the remaining filling regions retain their default colors. I suppose a Table using Mod[k,2] to maps odd and even numbers to Red, Blue would work but it's awful to have to compute and pass the number of segments. – alancalvitti Jun 26 '12 at 3:13
sorry... this should work: PlotStyle -> {Red, Blue}, FillingStyle -> Table[i -> If[OddQ[i], Red, Blue], {i, 200}], ColorFunctionScaling -> False 200 should be replace with the length of the list produced by Split – kglr Jun 26 '12 at 3:20
up vote 4 down vote accepted

Wrapping InputForm around your code will explain why the plot line is blue and not red.

FillingStyle is rather limited.


means that everything above your line to the filling point will be red and everything below the line to the filling point will be blue. Since your filling point is Bottom you should only see blue filling.


Plot[Sin[x], {x, 0, 2 Pi}, Filling -> Bottom, FillingStyle -> {Red,Blue}]


Plot[Sin[x], {x, 0, 2 Pi}, Filling -> Axis, FillingStyle -> {Red,Blue}]
share|improve this answer
Mike, thx for explaining. Fyi InputForm for the my code is way too long to parse manually, consisting of thousands of graphical elements... Also, I accepted your answer but would still like to know a run-around using ColorFunction if possible. You owe me... just kiddin. – alancalvitti Jun 26 '12 at 3:09
to the best of my knowledge this is not a ColorFunction issue, nor is that the place to look for a solution. @kguler has pointed in the right direction with specific rules but I would do it a bit differently -- depending on what you want the product to look like. While what you got is what I'd expect you to get it is unclear to me what you want the final plot to look like. Can you please explain/expand. – Mike Honeychurch Jun 26 '12 at 4:07

Using randomdata (do not have access to FinancialData at the time): with

randomdata = Thread[{DateList[{1980, 1, #}] & /@ Range[500],  RandomReal[{5000, 15000}, {500}]}];
inpdta = Split[randomdata,Not@(#[[2]] > 10000 && #2[[2]] <= 10000) &];


 Labeled[DateListPlot[#, Joined -> True, ImageSize -> 1000, AspectRatio -> 1/5, 
 Frame -> {True, True, False, False}, 
 Filling -> Bottom, PlotStyle -> {Red, Blue}, 
 FillingStyle -> Table[i -> If[OddQ[i], Red, Blue], {i, Length@inpdta}], 
 ColorFunctionScaling -> False,  
 GridLines -> None] &@  inpdta,
   Style["Dow Jones Industial 1.1.80-6.22.12 segmented by 10k crossings", Gray, Opacity[0.8], FontFamily -> "Helvetica"], Bottom]

you get

enter image description here

EDIT: Splitting the data produces white lines between sub-series. For several alternatives to get rid of these artifacts pls see this question and answers.

EDIT 2: Without having to pre-split the data and using ColorFunction (with a portion of the data)

 DateListPlot[randomdata[[1 ;; 100]], Joined -> True, Filling -> Bottom, 
 ColorFunction -> Function[{x, y}, Switch[Boole[y < 10000], 1, Red, 0, Blue]], 
 ColorFunctionScaling -> False]

enter image description here

EDIT 3: The following is perhaps the simplest way to get the same plot. The key step is to take every other part of list of sub-series produced by Split and overlay it (using Show) on top of a plain listplot of the source data. The added advantage is that you don't get coloring artifacts around the boundaries of regions.

 Show[DateListPlot[randomdata, Joined -> True, Filling -> Bottom, 
  PlotStyle -> Red, FillingStyle -> Red], 
  DateListPlot[Split[randomdata, Not@(#[[2]] > 10000 && #2[[2]] <= 10000) &][[1 ;; -1 ;; 2]], 
  Joined -> True, Filling -> Bottom, PlotStyle -> Blue, FillingStyle -> Blue]]

enter image description here

share|improve this answer
Very nice solutions, particularly edits #2 and #3 - thanks kguler – alancalvitti Jun 27 '12 at 2:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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