3
$\begingroup$

I have a list of values like this:

enter image description here

When I plot this data using DateListPlot[data] I get a plot connecting the individual points such as:

enter image description here

My question are:

  1. How can I create the same plot but only getting the individual points without connect them by line?. Similar to the plot below:
  2. How can I get the AM or PM from the times and put them in the x-axis?
  3. How can I space the time to be every 5 minutes when plotting the data (similar to the picture below)?

EDIT:

The data is the following:

{{DateObject[{2020, 7, 5, 8, 1, 0.}, "Instant", "Gregorian", -5.], 
  122.}, {DateObject[{2020, 7, 5, 8, 6, 0.}, "Instant", 
   "Gregorian", -5.], 
  108.}, {DateObject[{2020, 7, 5, 8, 11, 0.}, "Instant", 
   "Gregorian", -5.], 
  99.}, {DateObject[{2020, 7, 5, 8, 16, 0.}, "Instant", 
   "Gregorian", -5.], 
  101.}, {DateObject[{2020, 7, 5, 8, 21, 0.}, "Instant", 
   "Gregorian", -5.], 
  106.}, {DateObject[{2020, 7, 5, 8, 26, 0.}, "Instant", 
   "Gregorian", -5.], 
  110.}, {DateObject[{2020, 7, 5, 8, 31, 0.}, "Instant", 
   "Gregorian", -5.], 
  112.}, {DateObject[{2020, 7, 5, 8, 36, 0.}, "Instant", 
   "Gregorian", -5.], 
  102.}, {DateObject[{2020, 7, 5, 8, 41, 0.}, "Instant", 
   "Gregorian", -5.], 
  96.}, {DateObject[{2020, 7, 5, 8, 46, 0.}, "Instant", 
   "Gregorian", -5.], 
  96.}, {DateObject[{2020, 7, 5, 8, 51, 0.}, "Instant", 
   "Gregorian", -5.], 
  94.}, {DateObject[{2020, 7, 5, 8, 56, 0.}, "Instant", 
   "Gregorian", -5.], 
  92.}, {DateObject[{2020, 7, 5, 9, 1, 0.}, "Instant", 
   "Gregorian", -5.], 
  95.}, {DateObject[{2020, 7, 5, 9, 6, 0.}, "Instant", 
   "Gregorian", -5.], 
  98.}, {DateObject[{2020, 7, 5, 9, 11, 0.}, "Instant", 
   "Gregorian", -5.], 
  93.}, {DateObject[{2020, 7, 5, 9, 16, 0.}, "Instant", 
   "Gregorian", -5.], 
  84.}, {DateObject[{2020, 7, 5, 9, 21, 0.}, "Instant", 
   "Gregorian", -5.], 
  80.}, {DateObject[{2020, 7, 5, 9, 26, 0.}, "Instant", 
   "Gregorian", -5.], 
  78.}, {DateObject[{2020, 7, 5, 9, 31, 0.}, "Instant", 
   "Gregorian", -5.], 
  74.}, {DateObject[{2020, 7, 5, 9, 36, 0.}, "Instant", 
   "Gregorian", -5.], 
  60.}, {DateObject[{2020, 7, 5, 9, 41, 0.}, "Instant", 
   "Gregorian", -5.], 
  54.}, {DateObject[{2020, 7, 5, 9, 46, 0.}, "Instant", 
   "Gregorian", -5.], 
  57.}, {DateObject[{2020, 7, 5, 9, 51, 0.}, "Instant", 
   "Gregorian", -5.], 
  59.}, {DateObject[{2020, 7, 5, 9, 56, 0.}, "Instant", 
   "Gregorian", -5.], 68.}}
$\endgroup$
  • 1
    $\begingroup$ use the option Joined -> False? $\endgroup$ – kglr Jul 6 at 3:12
  • $\begingroup$ @kglr thank you! I was not aware this simple trick as possible!. Is there something similar like this to put the AM or PM values of the times in the x-axis? $\endgroup$ – John Jul 6 at 3:14
9
$\begingroup$

Q1. Use the option Joined -> False:

DateListPlot[data, Joined -> False]

enter image description here

Q2. Use the option DateTicksFormat "to put the AM or PM values of the times in the x-axis":

DateListPlot[data, Joined -> False, 
 DateTicksFormat -> {"Hour", ":", "Minute", "AMPM"}]

enter image description here

Q3. Specify the date ticks using DateRange with {5, "Minute"} as the increment:

dticks = DateRange[##, {5, "Minute"}] & @@ MinMax[data[[All,1]]];

DateListPlot[data, Joined -> False, 
 DateTicksFormat -> {"HourShort", ":", "Minute", "\n", "AMPM"}, 
 FrameTicks -> {{Automatic, Automatic}, {dticks, Automatic}}, 
 ImageSize -> 800]

enter image description here

To get more control on formatting of date tick labels, you can use a custom labeling function:

ClearAll[dateFormat]
dateFormat[d_] := Column[DateString[d, #] & /@ {{"HourShort", ":", "Minute"}, "AMPM"}, 
   Alignment -> Center, Spacings -> 0]

DateListPlot[data, Joined -> False, 
 FrameTicks -> {{Automatic, Automatic}, 
   {{#, dateFormat @ #} & /@ dticks, Automatic}}, 
 ImageSize -> 800]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ kglr thank you! This is exactly what I wanted for the first question! I really appreciate. I put a 3 question similar to this as well. I imagine it must be something simple as well. $\endgroup$ – John Jul 6 at 3:22
  • 1
    $\begingroup$ @John please see the updated version. $\endgroup$ – kglr Jul 6 at 3:56
  • $\begingroup$ kglr thank you this is great!. However, the line FrameTicks -> {{Automatic, Automatic}, {DateRange[#, #2, {5, "Minute"}] &, Automatic}} does not work. It shows "Transpose: the first two levels of {<<1>>} cannot be transposed". How can I fix that? $\endgroup$ – John Jul 6 at 17:25
  • $\begingroup$ @John, I updated with a variant that works in version 12.0+. $\endgroup$ – kglr Jul 8 at 6:02
  • $\begingroup$ kglr thank you very much! I accepted your answer. I appreciate it ! $\endgroup$ – John Jul 9 at 1:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.