3
$\begingroup$

I want to combine a TimeLinePlot and a DataListPlot. For both I use the same periode. The problem is that both X-axis differ when I make a overlay.

There are two datasets. The first one is about events to create a timeline:

events2017 = {{DateObject[{2017, 1, 3}, "Day", "Gregorian",     2.`], {"Tuesday  ", "event1"}}, {DateObject[{2017, 1, 17}, "Day",     "Gregorian", 2.`], {"Tuesday",     "event2"}}, {DateObject[{2017, 2, 10}, "Day", "Gregorian", 
2.`], {"Friday", "event3"}}, {DateObject[{2017, 2, 14}, "Day",     "Gregorian", 2.`], {"Tuesday",     "event4"}}, {DateObject[{2017, 2, 16}, "Day", "Gregorian",     2.`], {"Thursday ", "event5"}}, {DateObject[{2017, 2, 17}, "Day",     "Gregorian", 2.`], {"Friday",     "event6"}}, {DateObject[{2017, 2, 21}, "Day", "Gregorian",     2.`], {"Tuesday  ", "event7"}}, {DateObject[{2017, 3, 8}, "Day",     "Gregorian", 2.`], {"Wednesday",     "event8"}}, {DateObject[{2017, 3, 24}, "Day", "Gregorian",     2.`], {"Friday", "event9"}}, {DateObject[{2017, 3, 27}, "Day",     "Gregorian", 2.`], {"Monday",     "event10"}}, {DateObject[{2017, 3, 28}, "Day", "Gregorian",     2.`], {"Tuesday", "event11"}}, {DateObject[{2017, 4, 6}, "Day",     "Gregorian", 2.`], {"Thursday",     "event12"}}, {DateObject[{2017, 4, 7}, "Day", "Gregorian", 
2.`], {"Friday", "event13"}}, {DateObject[{2017, 4, 24}, "Day",     "Gregorian", 2.`], {"Monday",     "event14"}}, {DateObject[{2017, 4, 26}, "Day", "Gregorian",     2.`], {"Wednesday", "event15"}}, {DateObject[{2017, 5, 5}, "Day",     "Gregorian", 2.`], {"Friday",     "event16"}}, {DateObject[{2017, 5, 11}, "Day", "Gregorian",     2.`], {"Thursday", "event17"}}, {DateObject[{2017, 5, 16}, "Day",     "Gregorian", 2.`], {"Tuesday  ",     "event18"}}, {DateObject[{2017, 5, 22}, "Day", "Gregorian",     2.`], {"Monday", "event19"}}, {DateObject[{2017, 5, 24}, "Day",     "Gregorian", 2.`], {"Wednesday", "event20"}}
};

events2017tl = 
 TimelinePlot[
  MapThread[Labeled, {events2017[[All, 1]], events2017[[All, 2]]}], 
  ImageSize -> 1000]

enter image description here The second data sets is about the number of visitors at a specific day.(There ar no visitors in the weekend)

Visitors = {{DateObject[{2017, 1, 2, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    21}, {DateObject[{2017, 1, 3, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 1, 4, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 1, 5, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 1, 6, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 1, 9, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 1, 10, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 1, 11, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 1, 12, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 1, 13, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 23}, {DateObject[{2017, 1, 16, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 1, 17, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 1, 18, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 1, 19, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 1, 20, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 1, 23, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 1, 24, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    21}, {DateObject[{2017, 1, 25, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 1, 26, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 1, 27, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 1, 30, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 1, 31, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 2, 1, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 2, 2, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 2, 3, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 2, 6, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 2, 7, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 2, 8, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 2, 9, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 2, 10, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 2, 13, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 2, 14, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 2, 15, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 2, 16, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 23}, {DateObject[{2017, 2, 17, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 2, 20, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 2, 21, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 2, 22, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`],    22}, {DateObject[{2017, 2, 23, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 2, 24, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    21}, {DateObject[{2017, 2, 27, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 21}, {DateObject[{2017, 2, 28, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 3, 1, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 3, 2, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 3, 3, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 23}, {DateObject[{2017, 3, 6, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    23}, {DateObject[{2017, 3, 7, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 23}, {DateObject[{2017, 3, 8, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    23}, {DateObject[{2017, 3, 9, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 24}, {DateObject[{2017, 3, 10, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    24}, {DateObject[{2017, 3, 13, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`],    24}, {DateObject[{2017, 3, 14, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 23}, {DateObject[{2017, 3, 15, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    24}, {DateObject[{2017, 3, 16, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 24}, {DateObject[{2017, 3, 17, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    24}, {DateObject[{2017, 3, 20, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 23}, {DateObject[{2017, 3, 21, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    23}, {DateObject[{2017, 3, 22, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 23}, {DateObject[{2017, 3, 23, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    23}, {DateObject[{2017, 3, 24, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 23}, {DateObject[{2017, 3, 27, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    23}, {DateObject[{2017, 3, 28, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 23}, {DateObject[{2017, 3, 29, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    23}, {DateObject[{2017, 3, 30, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`],    23}, {DateObject[{2017, 3, 31, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 23}, {DateObject[{2017, 4, 3, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    23}, {DateObject[{2017, 4, 4, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 23}, {DateObject[{2017, 4, 5, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    23}, {DateObject[{2017, 4, 6, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 23}, {DateObject[{2017, 4, 7, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 4, 10, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 4, 11, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    23}, {DateObject[{2017, 4, 12, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 4, 13, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 4, 14, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 4, 17, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 4, 18, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`],    22}, {DateObject[{2017, 4, 19, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 4, 20, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    22}, {DateObject[{2017, 4, 21, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 23}, {DateObject[{2017, 4, 24, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    24}, {DateObject[{2017, 4, 25, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 24}, {DateObject[{2017, 4, 26, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    24}, {DateObject[{2017, 4, 27, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 24}, {DateObject[{2017, 4, 28, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    24}, {DateObject[{2017, 5, 1, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 25}, {DateObject[{2017, 5, 2, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    25}, {DateObject[{2017, 5, 3, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 25}, {DateObject[{2017, 5, 4, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    25}, {DateObject[{2017, 5, 5, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`],    26}, {DateObject[{2017, 5, 8, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 25}, {DateObject[{2017, 5, 9, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    25}, {DateObject[{2017, 5, 10, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 25}, {DateObject[{2017, 5, 11, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    25}, {DateObject[{2017, 5, 12, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 25}, {DateObject[{2017, 5, 15, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    24}, {DateObject[{2017, 5, 16, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 24}, {DateObject[{2017, 5, 17, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    23}, {DateObject[{2017, 5, 18, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 23}, {DateObject[{2017, 5, 19, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    24}, {DateObject[{2017, 5, 22, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 23}, {DateObject[{2017, 5, 23, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    23}, {DateObject[{2017, 5, 24, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`],    24}, {DateObject[{2017, 5, 25, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 23}, {DateObject[{2017, 5, 26, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    23}, {DateObject[{2017, 5, 29, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 23}, {DateObject[{2017, 5, 30, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    23}, {DateObject[{2017, 5, 31, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 23}, {DateObject[{2017, 6, 1, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    23}, {DateObject[{2017, 6, 2, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 23}, {DateObject[{2017, 6, 5, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    23}, {DateObject[{2017, 6, 6, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 22}, {DateObject[{2017, 6, 7, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    23}, {DateObject[{2017, 6, 8, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 23}, {DateObject[{2017, 6, 9, 0, 0, 0.`}, "Instant",     "Gregorian", 2.`],    23}, {DateObject[{2017, 6, 12, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`],    23}, {DateObject[{2017, 6, 13, 0, 0, 0.`}, "Instant", "Gregorian", 
2.`], 23}
};

The dataset look like

vistotorsdlp = DateListPlot[vistotors, ImageSize -> 1000]

enter image description here

Then I combine both plots using:

Overlay[{vistotorsdlp, events2017tl}, Alignment -> Bottom]

As you can see, the x-axes of both plots are different. My goal is to create one plot with the same x-axes. Who has a suggestion?

enter image description here

$\endgroup$
  • 2
    $\begingroup$ You have definitely different time ranges in both datasets and, therefore, different boundaries of the x-axis. Did you try the manual definition of the same PlotRange for both plots? Let's say, 01.01.17 - 15.06.17? $\endgroup$ – Rom38 Aug 18 '17 at 8:23
1
$\begingroup$

╮(╯▽╰)╭

events2017tl = TimelinePlot[ MapThread[Labeled, {events2017[[All, 1]], events2017[[All, 2]]}],  ImageSize -> 1000, PlotRange -> {{2017, 1, 2}, {2017, 6, 13}}];
vistotorsdlp = DateListPlot[{#1, 4.5 (#2 - 21)} & @@@ Visitors, ImageSize -> 1000, PlotStyle -> {Purple}];
Framed[Show[{events2017tl, vistotorsdlp}]]
$\endgroup$
  • $\begingroup$ Do you have a suggestion how to visualize the original y-axes from the datalistplot? $\endgroup$ – Michiel van Mens Aug 22 '17 at 6:47

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.