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.

I have the following datasets:

dataset1={{{1997}, 98/79}, {{1998}, 26/61}, {{1999}, 22/15}, {{2000}, 100/
  63}, {{2007}, 284/57}, {{2008}, 226/31}, {{2009}, 15/4}, {{2010}, 
  221/63}};

dataset2={{{1997}, 25/79}, {{1998}, 17/61}, {{1999}, 28/25}, {{2000}, 20/
  21}, {{2007}, 106/57}, {{2008}, 128/31}, {{2009}, 59/16}, {{2010}, 
  32/9}};

I want to plot them using DateListPlot[{dataset1,dataset2}] (plus appropriate additions, such as Joined, etc.). Note, however, that there is a missing gap here: the years 2001 through 2006. I have multiple datasets (over five of them) so the dots can be hard to understand. If I use the Filling->Bottom addition, it cleans it up a bit, but still a bit hard. If I use Joined->true, it just connects 2000 and 2007 (as it should) but this implies data that I don't have.

Is there a way, using Mathematica, to connect the points for the years 1997 through 2000 and the years 2007 through 2010 - but not to draw a line in the middle between 2000 and 2007, as that skews the data?

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

Add in a Null data point to each series like this:

dataset1 = {{{1997}, 98/79}, {{1998}, 26/61}, {{1999}, 
    22/15}, {{2000}, 100/63}, {{2001}, Null}, {{2007}, 
    284/57}, {{2008}, 226/31}, {{2009}, 15/4}, {{2010}, 221/63}};

dataset2 = {{{1997}, 25/79}, {{1998}, 17/61}, {{1999}, 
    28/25}, {{2000}, 20/21}, {{2001}, Null}, {{2007}, 
    106/57}, {{2008}, 128/31}, {{2009}, 59/16}, {{2010}, 32/9}};

The plot then becomes:

DateListPlot[{dataset1, dataset2}, Joined -> True]

enter image description here

share|improve this answer
    
Do you know if this works in general for, say ListPlot? –  tkott Apr 19 '12 at 20:49
    
@tkott Yes, it does. –  Sjoerd C. de Vries Apr 19 '12 at 20:52
    
You could add a function like this parseList[list_, threshold_] := Module[{tag}, Reap[ Fold[(If[Abs@DateDifference[First@#2, First@#1] > threshold, Sow[{First@#1, Null}, tag]]; Sow[#2, tag]) &, First@list, Rest@list], tag][[2 , 1]]] to parse the list, where threshold is given in days –  Rojo Apr 19 '12 at 21:17
    
unrelated, but looking at the plot above I want to remind everybody about the option GridLines->False, which together with Frame->{True,True,False,False}, allow Edward Tufte to sleep at night. –  Michael Stern Apr 20 '12 at 16:08
add comment

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.