Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Given this dataset (~2100 year precipitation estimates in New Mexico, based on tree-ring data, courtesy of NOAA and Henri Grissino-Mayer)

MALPAIS[1] = ToExpression@StringSplit[#, " "] & /@ 
 StringSplit[
  StringTake[
   Import["ftp://ftp.ncdc.noaa.gov/pub/data/paleo/treering/\
reconstructions/newmexico/malpais_recon.txt"], 18669 ;; 44215], "\n"]

The following:

ListLinePlot[#, Frame -> True, Axes -> False, Filling -> Axis, 
       AspectRatio -> 1/5, ImageSize -> 1000, 
       ColorFunction -> Function[{x, y}, If[y < 0, Red, Blue]], 
       ColorFunctionScaling -> False] & @(MALPAIS[1] - 
       15.3146`)

Results in color-bleed (note, I switched colors from above):

enter image description here

Presumably due to interpolation, since it it's also there in smaller time windows:

enter image description here

Is there any option to prevent this?

share|improve this question
add comment

1 Answer 1

up vote 5 down vote accepted

FillingStyle is the clue here:

GraphicsColumn@{
   ListLinePlot[#[[;; 50]], 
       Frame -> True, Axes -> False,Filling -> Axis, AspectRatio -> 1/5, 
       ImageSize -> 1000, ColorFunction -> Function[{x, y}, If[y < 0, Red, Blue]],
       ColorFunctionScaling -> False],
    ListLinePlot[#[[;; 50]], 
       Frame -> True, Axes -> False, Filling -> Axis, AspectRatio -> 1/5, 
       ImageSize -> 1000, FillingStyle -> {Red, Blue},   
       ColorFunction -> Function[{x, y}, If[y < 0, Red, Blue]], 
       ColorFunctionScaling -> False]
} &@(MALPAIS[1] - 15.3146`)

Mathematica graphics

Whole scale (now with ColorFunction removed and without style):

ListLinePlot[#[[;; -1]], Frame -> True, Axes -> False, 
    Filling -> Axis, AspectRatio -> 1/5, ImageSize -> 1000, 
    FillingStyle -> {Red, Blue}, PlotStyle -> None]} &@(MALPAIS[1] - 
   15.3146`

Mathematica graphics

Arbitrary function to determine separation between blue and red (requested per comment):

ListLinePlot[{#[[;; 50]], Table[{x, Sin[x/4]}, {x, #[[;; 50, 1]]}]}, 
   Frame -> True, Axes -> False, Filling -> {2}, AspectRatio -> 1/5, 
   ImageSize -> 1000, FillingStyle -> {Red, Blue}, 
   PlotStyle -> None] &@(MALPAIS[1] - 15.3146`)

Mathematica graphics

share|improve this answer
    
Is it necessary to pass the colors to both FillingStyle and ColorFunction? Seems redundant. –  alancalvitti Aug 16 '12 at 21:31
    
+1 for the idea. But @alancalvitti is right, ColorFunction needs to be removed. –  Vitaliy Kaurov Aug 16 '12 at 21:32
    
@alancalvitti It is. I did it first without (setting Style->None) and it's just fine. However, having a line as boundary seems to add a bit of anti-aliasing that I found to be slightly neater. I guess, effects will differ by platform. –  Sjoerd C. de Vries Aug 16 '12 at 21:35
    
@VitaliyKaurov Not definitely so, see comment above. –  Sjoerd C. de Vries Aug 16 '12 at 21:36
    
But what If I hadn't detrended the time series mean, in other words, how to get filling to some nonzero constant k: Function[{x, y}, If[y < k, Red, Blue]] Or even more general function? –  alancalvitti Aug 16 '12 at 21:37
show 8 more comments

Your Answer

 
discard

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.