2
$\begingroup$

I'm trying to plot energy usage over time using datelistplot but the time zone on the ticks is wrong, data for 7pm shows as 3am The code:

Manipulate[
    Labeled[
        DateListPlot[
            Databin["66xNhqQ2"] , 
            DateTicksFormat->{
                "DayNameShort", " ", "Day", " ",  "Hour12", ":", "Minute", "AMPM"},        Filling->Bottom, 
            FrameLabel->{
                {None,  None}, {"Time", None}}
            ]["power"], 
    "Power Usage in 2 Minutes (watt hours)", 
    {Top}]
]
$\endgroup$

1 Answer 1

0
$\begingroup$

This might be the problem: The date axis is automatic. Note the time for the datapoint value 6 is 9pm. The axis automatically shows a tick label at 10pm.

data = {
   {{2015, 7, 28, 18, 0, 0}, 3},
   {{2015, 7, 28, 21, 0, 0}, 6},
   {{2015, 7, 29, 4, 0, 0}, 1},
   {{2015, 7, 29, 6, 0, 0}, 2}};

DateListPlot[data, DateTicksFormat ->
  {"DayNameShort", " ", "Day", " ", "Hour12", ":", "Minute", "AMPM"},
 Filling -> Bottom, FrameLabel -> {{None, None}, {"Time", None}}]

enter image description here

You can customise the frame ticks to show the datapoint times like so:

hours = DateDifference[data[[1, 1]], data[[-1, 1]], "Hour"][[1]];

datehours = # + data[[1, 1, 4]] - 1 & /@ Range[hours + 1];

alldates = Chop@DateList[Append[data[[1, 1, 1 ;; 3]], #]] & /@ datehours;

datestrings = Join[{""}, If[MemberQ[First /@ data, #],
      DateString[#, {"DayNameShort", " ", "Day", " ", "Hour12",
        ":", "Minute", "AMPM"}], ""] & /@ alldates[[2 ;; -2]], {""}];

frameticks = {Transpose[{alldates, datestrings}], Automatic};

DateListPlot[data,
 Filling -> Bottom, FrameLabel -> {{None, None}, {"Time", None}},
 FrameTicks -> frameticks]

enter image description here

$\endgroup$
2
  • $\begingroup$ The first data point is at 6pm and the plot shows data for 3am $\endgroup$ Jul 31, 2015 at 4:08
  • $\begingroup$ If you can add some data to demonstrate the problem that would help. $\endgroup$ Jul 31, 2015 at 6:14

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