5

The documentation that I can find suggests that I should be able to plot an EventSeries with DateListPlot. But this doesn't work for me.

For example

sunrises=Sunrise[DateRange[DateObject[{2014,1,1}],DateObject[{2015,1,1}],{5,"Day"}]];
DateListPlot[sunrises]

gives

enter image description here

orome
  • 12,819
  • 3
  • 52
  • 100

3 Answers3

7

The issue here is that Sunrise packages up an EventSeries that is kind of wonky for what you are trying to do. The values are all DateObject which don't lend themselves to plotting on the y-axis.

sunrises=Sunrise[DateRange[DateObject[{2014,1,1}],DateObject[{2015,1,1}],{5,"Day"}]];

sunrises["Values"][[1]] // InputForm
(* DateObject[{2014, 1, 1}, TimeObject[{7, 29}, TimeZone -> -6.], TimeZone -> -6.] *)

What you want to visualize is the time of day so you need to convert those values. Since all of the time series functionality works with EventSeries you can use TimeSeriesMap.

DateListPlot@TimeSeriesMap[(#["Hour24"] + #["Minute"]/60) &, sunrises]

enter image description here

Andy Ross
  • 19,320
  • 2
  • 61
  • 93
5

I found the predictive interface helpful for working out the following.

sunrises = 
  Sunrise[
    DateRange[DateObject[{2014, 1, 1}], DateObject[{2015, 1, 1}], 
    {5, "Day"}]]["Values"];
times = 
  Module[{h, m}, 
    {h, m} = DateValue[#, {"Hour", "Minute"}]; 
    h + m/60.]& /@ sunrises;
DateListPlot[Transpose[{sunrises, times}]]

plot

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
  • How you yo get a TARDIS?! – orome Dec 24 '15 at 14:58
  • @raxacoricofallapatorius. There is one built into every Mathematica notebook :-) Really, between the predictive interface and the documentation, it only took a few minutes to work this out. – m_goldberg Dec 24 '15 at 15:19
2
sunrises = DateRange[DateObject[{2014, 1, 1}], DateObject[{2015, 1, 1}], {5, "Day"}];

DateListPlot@Transpose[{sunrises, DateList /@ Sunrise /@ sunrises /. 
  {_, _, _, h_, m_, _} :> h + m/60.}]

enter image description here

eldo
  • 67,911
  • 5
  • 60
  • 168
  • How do I examine an EventSeries to discover that this is necessary? – orome Dec 24 '15 at 14:12
  • 1
    You need two different things. (1) dates, here sunrises, and (2) values, here h + m/60.. Dates and values have to be transposed do that every date has a value attached. {{{2014, 1, 1}, value1}, {{2014, 1, 2}, value2}, ...} – eldo Dec 24 '15 at 14:23