# Inconsistent TimelinePlot Layout when using time intervals

**URL:** <https://community.wolfram.com/t/inconsistent-timelineplot-layout-when-using-time-intervals/18992>\
**Category:** Questions\
**Tags:** business-analytics, graphics-and-visualization\
**Created:** [October 18, 2021, 5:52pm UTC](https://community.wolfram.com/t/inconsistent-timelineplot-layout-when-using-time-intervals/18992 "2021-10-18T17:52:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![davepmiddleton](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/davepmiddleton/32/40539_2.png) [@davepmiddleton](https://community.wolfram.com/u/davepmiddleton)\
**Post date:** [October 18, 2021, 5:52pm UTC](https://community.wolfram.com/t/inconsistent-timelineplot-layout-when-using-time-intervals/18992/1 "2021-10-18T17:52:21Z")

</div>

When processing usage logs from an online conferencing platform, I wanted to plot time intervals in H:MM format in TimelinePlot which shows the following issues:

1. It does not display the intervals consistently i.e. one timeline is grouped whereas the other is stacked in the same plot. The display cannot be changed in PlotLayout.
2. The vertical axis cuts through the timelines i.e. are not aligned. Manually setting PlotRange.did not help.

As an example, I provide the data to generate the TimelinePlot. When I replace the intervals by e.g. DateObject[{year}] format, all works fine.

Is there an issue with the TimelinePlot or I am missing something? Thanks.

```
<|"Name1" -> {Interval[{DateObject[{2021, 10, 15, 19, 1, 18.`}, 
       "Instant", "Gregorian", -5.`], 
      DateObject[{2021, 10, 15, 20, 7, 28.`}, "Instant", 
       "Gregorian", -5.`]}]}, 
  "Name2" -> {Interval[{DateObject[{2021, 10, 15, 19, 1, 29.`}, 
       "Instant", "Gregorian", -5.`], 
      DateObject[{2021, 10, 15, 19, 51, 3.`}, "Instant", 
       "Gregorian", -5.`]}], 
    Interval[{DateObject[{2021, 10, 15, 19, 53, 29.`}, "Instant", 
       "Gregorian", -5.`], 
      DateObject[{2021, 10, 15, 20, 6, 36.`}, "Instant", 
       "Gregorian", -5.`]}]}, 
  "name3" -> {Interval[{DateObject[{2021, 10, 15, 19, 1, 30.`}, 
       "Instant", "Gregorian", -5.`], 
      DateObject[{2021, 10, 15, 19, 1, 39.`}, "Instant", 
       "Gregorian", -5.`]}], 
    Interval[{DateObject[{2021, 10, 15, 19, 1, 40.`}, "Instant", 
       "Gregorian", -5.`], 
      DateObject[{2021, 10, 15, 19, 57, 19.`}, "Instant", 
       "Gregorian", -5.`]}]}, 
  "name4" -> {Interval[{DateObject[{2021, 10, 15, 19, 1, 41.`}, 
       "Instant", "Gregorian", -5.`], 
      DateObject[{2021, 10, 15, 19, 1, 55.`}, "Instant", 
       "Gregorian", -5.`]}], 
    Interval[{DateObject[{2021, 10, 15, 19, 1, 56.`}, "Instant", 
       "Gregorian", -5.`], 
      DateObject[{2021, 10, 15, 20, 5, 59.`}, "Instant", 
       "Gregorian", -5.`]}]}, 
  "name5" -> {Interval[{DateObject[{2021, 10, 15, 19, 1, 55.`}, 
       "Instant", "Gregorian", -5.`], 
      DateObject[{2021, 10, 15, 19, 26, 1.`}, "Instant", 
       "Gregorian", -5.`]}], 
    Interval[{DateObject[{2021, 10, 15, 19, 45, 1.`}, "Instant", 
       "Gregorian", -5.`], 
      DateObject[{2021, 10, 15, 20, 5, 55.`}, "Instant", 
       "Gregorian", -5.`]}]}, 
  "name6" -> {Interval[{DateObject[{2021, 10, 15, 19, 5, 22.`}, 
       "Instant", "Gregorian", -5.`], 
      DateObject[{2021, 10, 15, 19, 5, 31.`}, "Instant", 
       "Gregorian", -5.`]}], 
    Interval[{DateObject[{2021, 10, 15, 19, 5, 32.`}, "Instant", 
       "Gregorian", -5.`], 
      DateObject[{2021, 10, 15, 20, 5, 58.`}, "Instant", 
       "Gregorian", -5.`]}]}, 
  "Charles Packard" -> {Interval[{DateObject[{2021, 10, 15, 19, 27, 
        2.`}, "Instant", "Gregorian", -5.`], 
      DateObject[{2021, 10, 15, 20, 5, 54.`}, "Instant", 
       "Gregorian", -5.`]}]}|>;
TimelinePlot[%]

```

 ![TimelinePlot.png](https://global.discourse-cdn.com/wolfram/original/2X/8/84baacff7e9c8568094faf4cabf6bc77e7f0ff8e.png)

---

<div class="post-metadata">

**Author:** ![henrikschachner](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/henrikschachner/32/32119_2.png) [@henrikschachner](https://community.wolfram.com/u/henrikschachner)\
**Post date:** [October 18, 2021, 7:14pm UTC](https://community.wolfram.com/t/inconsistent-timelineplot-layout-when-using-time-intervals/18992/2 "2021-10-18T19:14:45Z")

</div>

Dave,

probably not the solution, but a problem could be that your time intervals are included in `List`; try:

```
assoc = <| --- your association --- |>
assoc1 = Association@KeyValueMap[#1 -> First[#2] &, assoc];
TimelinePlot[assoc1]

```

 ![timelineplot.png](https://global.discourse-cdn.com/wolfram/original/2X/3/3417b9774e96755da376d96d13739a20ed30d4a5.png)

---

<div class="post-metadata">

**Author:** ![rohitnamjoshi](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@rohitnamjoshi](https://community.wolfram.com/u/rohitnamjoshi)\
**Post date:** [October 18, 2021, 9:09pm UTC](https://community.wolfram.com/t/inconsistent-timelineplot-layout-when-using-time-intervals/18992/3 "2021-10-18T21:09:58Z")

</div>

Another way to remove the `List`

```
First /@ data // TimelinePlot

```

where `data` = the association.

---

<div class="post-metadata">

**Author:** ![henrikschachner](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/henrikschachner/32/32119_2.png) [@henrikschachner](https://community.wolfram.com/u/henrikschachner)\
**Post date:** [October 19, 2021, 5:37am UTC](https://community.wolfram.com/t/inconsistent-timelineplot-layout-when-using-time-intervals/18992/4 "2021-10-19T05:37:49Z")

</div>

Yes, definitely the better way - in `Association` keys are “transparent”!

---

<div class="post-metadata">

**Author:** ![davepmiddleton](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/davepmiddleton/32/40539_2.png) [@davepmiddleton](https://community.wolfram.com/u/davepmiddleton)\
**Post date:** [October 21, 2021, 3:30am UTC](https://community.wolfram.com/t/inconsistent-timelineplot-layout-when-using-time-intervals/18992/5 "2021-10-21T03:30:49Z")

</div>

Thanks everyone for the suggestions.

I reviewed my code with fresh eyes, found the issues and solved it (see example for many intervals).

 ![Screenshot 2021-10-20 222926.jpg](https://global.discourse-cdn.com/wolfram/original/3X/e/5/e55fa1ba3d4851e8af4d320c65e152b6f872e741.jpeg)

---

<div class="post-metadata">

**Author:** ![rohitnamjoshi](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@rohitnamjoshi](https://community.wolfram.com/u/rohitnamjoshi)\
**Post date:** [October 21, 2021, 2:19pm UTC](https://community.wolfram.com/t/inconsistent-timelineplot-layout-when-using-time-intervals/18992/6 "2021-10-21T14:19:28Z")

</div>

Hi Dave,

Nice! Would you mind sharing your solution so others can benefit from it in the future? I am guessing you did something like

```
data // Values // Flatten[#, 1] & // TimelinePlot

```

If you want to compute the number of concurrent viewers over time, take a look at [this](https://wolfram.discourse.group/t/14228/1) .

---

<div class="post-metadata">

**Author:** ![davepmiddleton](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/davepmiddleton/32/40539_2.png) [@davepmiddleton](https://community.wolfram.com/u/davepmiddleton)\
**Post date:** [October 22, 2021, 1:54pm UTC](https://community.wolfram.com/t/inconsistent-timelineplot-layout-when-using-time-intervals/18992/7 "2021-10-22T13:54:55Z")

</div>

Hi Rohit,

Thanks for the response. The answer is yes, but there is a bit of a story to it.

I already created concurrent user plots over time, which I named Attendance Charts/Plots.  
Since I collected a lot of data, these charts have more detail than the one in your link: [[?] Plot Video Conference engagement levels from log files?](https://wolfram.discourse.group/t/14228/1)

I had one chart left on my wish list: a “Gantt” chart (timeline) of attendance which I can use to review who signed-in and signed-out and when. This is the plot I shared.

The code I use is:

```
AttendanceTimeline[d_Dataset] := Module[{data, l, tlp},
  data = Query[GroupBy[#Name &], All, #Intervals &]@d;
  l = Length@data;
  ticks = Transpose[{Range[l], Normal@Keys@data}];
  tlp = TimelinePlot[
    DateInterval /@ 
     Flatten[Normal@
       Values@Query[GroupBy[#Name &], All, #Intervals &]@d, 1], 
    PlotStyle -> RGBColor[
     0.5058824656863051, 0.41960714747751615`, 0.28627398412570204`], 
    PlotLayout -> "Stacked"];
  Show[tlp, Frame -> {{True, True}, {True, True}}, 
   Options[tlp, FrameTicks] /. {None, None} -> {ticks, None}, 
   AspectRatio -> 1, GridLines -> {Automatic, Range[l]}, 
   GridLinesStyle -> Directive[
RGBColor[0.8784316204832701, 0.8392150364732718, 0.7529403241427501]]]
  ]

```

It uses a Dataset of participant names, Date (optional, superfluous but handy) and join-leave DateInterval (List). The latter was giving me trouble when creating a TimelinePlot.

Also I found this link on StackExchang which was of great help too:  
[https://mathematica.stackexchange.com/questions/151128/timelineplot-y-axis-misaligned](https://mathematica.stackexchange.com/questions/151128/timelineplot-y-axis-misaligned)

Anyway, if you are interested in how to analyze conferencing usage logs (e.g. Zoom or Teams), with visualization, I have to write a separate post on this topic.

Cheers,

Dave
