1
$\begingroup$

I'm trying to achieve something similar to this example mentioned in the mathematica website below (https://reference.wolfram.com/language/ref/TimelinePlot.html), except I'm trying to get the event dates and captions from given arrays.

enter image description here

// Given Date Interval Array
xDates = [
 {{1999, 03, 11}, {2000, 09, 11}},
 {{2011, 09, 11}, {2012, 05, 6}},
 {{2012, 06, 14}, {2014, 02, 12}},
 {{2014, 04, 14}, {2015, 09, 11}}
 ]

//Captions Array

xCaption = 
[
 {“Abc”},
 {“Def”},
 {“Ghi”},
 {“Jkl”}
]

and finally plotting the graph with

TimelinePlot[Labeled[Interval[xDates], xCaptions]]
$\endgroup$
4
$\begingroup$

First, your xDates and xCaptions are not correctly formatted: you have to get rid of the outer square brackets:

xDates = {{{1999, 03, 11}, {2000, 09, 11}}, {{2011, 09, 11}, {2012, 05, 6}},
{{2012, 06, 14}, {2014, 02, 12}}, {{2014, 04, 14}, {2015, 09, 11}}};
xCaptions = Flatten@{{"Abc"}, {"Def"}, {"Ghi"}, {"Jkl"}};

Additionally, Flatten the original xCaptions so it's a list of strings, not a list of single-element lists.

Then, put it in a format that TimelinePlot will understand:

lab = Table[Labeled[Interval[xDates[[i]]], xCaptions[[i]]], {i, 1, Length@xDates}];

and finally

TimelinePlot[lab]

enter image description here

$\endgroup$
  • $\begingroup$ Many thanks. I was stuck for days :) $\endgroup$ – Naveed Abbas Sep 7 '16 at 9:45

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.