5
$\begingroup$

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

$\endgroup$
7
$\begingroup$

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

$\endgroup$
  • $\begingroup$ How do I get rid of the "chunkiness" of the plot? It should be much smoother. $\endgroup$ – orome Dec 25 '15 at 14:16
5
$\begingroup$

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

$\endgroup$
  • $\begingroup$ How you yo get a TARDIS?! $\endgroup$ – orome Dec 24 '15 at 14:58
  • $\begingroup$ @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. $\endgroup$ – m_goldberg Dec 24 '15 at 15:19
2
$\begingroup$
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

$\endgroup$
  • $\begingroup$ How do I examine an EventSeries to discover that this is necessary? $\endgroup$ – orome Dec 24 '15 at 14:12
  • 1
    $\begingroup$ 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}, ...} $\endgroup$ – eldo Dec 24 '15 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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