3
$\begingroup$

I made a TimeLinePlot to visualise intervals. Each interval starts with a marker en end with one.

For example:

TimelinePlot[
  {{Interval[{"Mar 20, 1990", "Jul 11, 2008"}]}, 
   {Interval[{"Sep 17, 1990", "Mar 14, 2005"}]}},
  PlotMarkers -> "Filled"]

This produces

enter image description here

Each interval line has a different color. I want both interval Lines to start with a red bullet and finish with a blue one.

How can I do that?

$\endgroup$

1 Answer 1

4
$\begingroup$
data = {{Interval[{"Mar 20, 1990", "Jul 11, 2008"}]}, 
  {Interval[{"Sep 17, 1990", "Mar 14, 2005"}]}};

1. You can pre-process input data to replace {Interval[{a, b}]} with {Interval[{a,b}], Style[a, Red], Style[b, Blue]} and use the option Spacings as follows:

data2 = data /. { i : Interval[{a_, b_}]} :> {i, Style[a, Red], Style[b, Blue]};

TimelinePlot[data2, Spacings -> {1, 0}, PlotMarkers -> {"Filled", .02}]

enter image description here

2. Alternatively, you can post-process TimelinePlot output to insert the desired directives:

tlp = TimelinePlot[data, PlotMarkers -> "Filled"];

Show[tlp, 
 Graphics[Cases[tlp, 
    PointBox[x_] :> Thread[{AbsolutePointSize[10], {Red, Blue}, Point /@ x}], All]]]

enter image description here

3. Use data to construct graphics primitives with desired styles to be used as Epilog in TimelinePlot:

epilog = MapIndexed[Thread[{AbsolutePointSize[10], {Red, Blue}, 
     Point /@ Thread[{#, #2[[1]]}]}] &, 
  Flatten[data] /. Interval -> Map[AbsoluteTime]];

TimelinePlot[data, Epilog -> epilog]

enter image description here

$\endgroup$
2
  • $\begingroup$ Nice, I like the first one. But, how is the transformation if the dataset looks like data = {Interval[{"Mar 20, 2020", "Jul 11, 2020"}], Interval[{"Sep 17, 2020", "Sep 20, 2020"}]} $\endgroup$ Aug 14, 2020 at 12:55
  • 1
    $\begingroup$ @MichielvanMens, you can use datab = {Interval[{"Mar 20, 1990", "Jul 11, 2008"}], Interval[{"Sep 17, 1990", "Mar 14, 2005"}]}; datab2 = datab /. i : Interval[{a_, b_}] :> {i, Style[a, Red], Style[b, Blue]}; TimelinePlot[datab2, Spacings -> {1, 0}, PlotMarkers -> {"Filled", .02}] $\endgroup$
    – kglr
    Aug 14, 2020 at 15:05

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.