5
$\begingroup$

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?

$\endgroup$
7
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Do you know if this works in general for, say ListPlot? $\endgroup$ – tkott Apr 19 '12 at 20:49
  • $\begingroup$ @tkott Yes, it does. $\endgroup$ – Sjoerd C. de Vries Apr 19 '12 at 20:52
  • $\begingroup$ 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 $\endgroup$ – Rojo Apr 19 '12 at 21:17
  • 1
    $\begingroup$ 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. $\endgroup$ – Michael Stern Apr 20 '12 at 16:08

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.