1
$\begingroup$

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]
$\endgroup$
5
  • $\begingroup$ Can you attach a pic of what you are seeing? $\endgroup$ Jun 26, 2012 at 2:49
  • $\begingroup$ Sure, what's the procedure for uploading a .png? $\endgroup$ Jun 26, 2012 at 2:51
  • $\begingroup$ Tried setting the options as Filling -> Axis, FillingStyle -> {1 -> Red, 2 -> Blue}, , ColorFunctionScaling->False? $\endgroup$
    – kglr
    Jun 26, 2012 at 3:04
  • $\begingroup$ @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. $\endgroup$ Jun 26, 2012 at 3:13
  • $\begingroup$ 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 $\endgroup$
    – kglr
    Jun 26, 2012 at 3:20

2 Answers 2

4
$\begingroup$

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

FillingStyle is rather limited.

FillingStyle->{Red,Blue}

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.

e.g.

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

and

Plot[Sin[x], {x, 0, 2 Pi}, Filling -> Axis, FillingStyle -> {Red,Blue}]
$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$ Jun 26, 2012 at 3:09
  • $\begingroup$ 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. $\endgroup$ Jun 26, 2012 at 4:07
3
$\begingroup$

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) &];

and

 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

$\endgroup$
1
  • $\begingroup$ Very nice solutions, particularly edits #2 and #3 - thanks kguler $\endgroup$ Jun 27, 2012 at 2:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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