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$

closed as off-topic by Karsten 7., dr.blochwave, MarcoB, ilian, Öskå Sep 28 '15 at 17:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – Karsten 7., dr.blochwave, MarcoB, ilian, Öskå
If this question can be reworded to fit the rules in the help center, please edit the question.

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$
  • $\begingroup$ The first data point is at 6pm and the plot shows data for 3am $\endgroup$ – minecraftwarlock Jul 31 '15 at 4:08
  • $\begingroup$ If you can add some data to demonstrate the problem that would help. $\endgroup$ – Chris Degnen Jul 31 '15 at 6:14

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