1
$\begingroup$

When plotting an Association of data in TimelinePlot the y-axis is labeled with the Keys. However the axis is not aligned to the data.

TimelinePlot@
 AssociationThread[{"a", "b", "c"}, ConstantArray[{{2017, 1, 1}, {2017, 1, 10}}, 3]]

enter image description here

I would turn off the y-axis with Axes but TimelinePlot ignores the y-axis specification.

TimelinePlot[
 AssociationThread[{"a", "b", "c"}, ConstantArray[{{2017, 1, 1}, {2017, 1, 10}}, 3]], 
 Axes -> {True, False}]

enter image description here

Does anyone else get this? Any ideas to have the y-axis align or remove it altogether? Actually, clicking on the y-axis seems to indicate the it is not an axis. So ...

Mma 11.1.1 on Win 7 Ent

$\endgroup$
  • $\begingroup$ Look at the InputForm and you'll see it's definitely not an axis, it's an Inset. You could do something like TimelinePlot[ AssociationThread[{"a", "b", "c"}, ConstantArray[{{2017, 1, 1}, {2017, 1, 10}}, 3]], PlotLayout -> "Stacked", Frame -> True] /. Inset[Graphics[prims_, opts__], moreOpts__] :> ReplaceAll[ prims, {0, y_Integer} :> {AbsoluteTime[{2016, 12, 31}], y}] $\endgroup$ – Jason B. Jul 10 '17 at 21:55
1
$\begingroup$
as = AssociationThread[{"a", "b", "c"}, ConstantArray[{{2017, 1, 1}, {2017, 1, 10}}, 3]];

To remove the labels you can use

 tlp = TimelinePlot[Values @ as] (* or *)
 tlp = TimelinePlot[as]/. _Inset->Nothing

enter image description here

To add labels on the y axis:

Show[tlp, Frame -> {{True, None}, {True, None}}, 
  Options[tlp, FrameTicks] /. {None, None} -> {MapIndexed[{#2[[1]], #}&, Keys[as]], None}]

enter image description here

Note: For thegeneral case where Spacings -> spacings option specified, tick specification above should change to

MapIndexed[{#2[[1]] spacings[[#2[[1]]]], #}&, Keys[as]]
$\endgroup$
2
$\begingroup$

This is the way the ref/TimelinePlot recommends making a time-list-plot with an association.

TimelinePlot @
  AssociationThread[{"a", "b", "c"}, 
  ConstantArray[Interval[{{2017, 1, 1}, {2017, 1, 10}}], 3]]

plot

Note the use of Interval.

The plot looks strange because the data is highly contrived, but the "a", "b", "c" labels give valuable information on mouse-over. The keys are not axes labels, but labels for the timelines.

$\endgroup$

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.