0
$\begingroup$

Problem

I'm tracking some DateObject data and I'm struggling to get the horizontal axis ticks to match the time in Pacific Standard Time (PST).

Data

data = {DateObject[{2018, 2, 26, 7, 43, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 8, 8, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 8, 28, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 8, 37, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 8, 45, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 8, 53, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 9, 47, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 10, 5, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 10, 9, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 10, 13, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 10, 27, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 10, 31, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 10, 33, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 10, 35, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 10, 52, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 10, 54, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 10, 57, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 11, 0, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 11, 7, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 11, 17, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 11, 28, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 11, 58, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 12, 31, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 1, 49, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 2, 2, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 2, 14, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 2, 15, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"]}

Visual

DateHistogram[data, 8, 
 LabelingFunction -> (Placed[Panel[#1, FrameMargins -> 0], Above] &), 
 Axes -> {True, False}, AxesOrigin -> {20, 0}]

enter image description here

Question

How do I make the tick mark labels match the actual times in PST? Can you please explain what the values correspond to?

$\endgroup$
7
  • $\begingroup$ It looks like the labels are correct to me. You have 4 entries between 1:45 and 3:30 (the last 4), 5 entries between 7:00 and 8:45 (the first 5), 6 between 8:45 and 10:30, 11 between 10:30 and 12:15, and one after 12:15. $\endgroup$
    – Carl Woll
    Feb 28, 2018 at 0:02
  • $\begingroup$ So then, how do I get the data to start at 7am, or some other time at the start of the day? $\endgroup$
    – Matt Green
    Feb 28, 2018 at 0:08
  • $\begingroup$ I’ve tried changing bin size also but I can’t find the correct syntax $\endgroup$
    – Matt Green
    Feb 28, 2018 at 0:14
  • $\begingroup$ Are your last 4 data points supposed to be in the afternoon? $\endgroup$
    – Carl Woll
    Feb 28, 2018 at 0:23
  • $\begingroup$ Yes they are. I’m struggling with using the AxesOrigin command correctly $\endgroup$
    – Matt Green
    Feb 28, 2018 at 2:08

2 Answers 2

1
$\begingroup$

Thank you Carl for showing me the solution. My data started in a Google Sheet and was then exported as a CSV. As I hand-entered my data I failed to enter afternoon times in 24 hour time. Changing this format and running the new CSV through my code worked great. The last four values in data are now:

{DateObject[{2018, 2, 26, 13, 49, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 14, 2, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 14, 12, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"], 
 DateObject[{2018, 2, 26, 14, 15, 0}, "Instant", "Gregorian", 
  "America/Los_Angeles"]}

The new visual looks like this:

enter image description here

In reference to the answer posted by Mitch, I'd already taken timezone into account when I mapped my DateObject function onto the list of datetimes:

data = Map[DateObject[#, TimeZone -> "America/Los_Angeles"] &, data]

The resulting list of DateObjects was then displayed using:

DateHistogram[data, 8, 
 LabelingFunction -> (Placed[Panel[#1, FrameMargins -> 0], Above] &), 
 Axes -> {True, False}]
$\endgroup$
0
$\begingroup$

I bump into this consideration frequently. Have a look at TimeZoneConvert[ ]. What really matters is that you know the time zone of the timestamp at data origination vs the time zone at the data display point. There is another level to all this. When you are 'serving' the data in the cloud (via Wolfram Cloud perhaps) where the data is saved matters as well. The fact that WC is CST, and the location of the device saving the data, as well as, the location of the device displaying the data, all matter to the end user.

I'll leave this answer at this, and after you review TimeZoneConvert[ ] if you still have questions please follow up.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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