How do I plot EventSeries?

5

2

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

Posted 2015-12-24T13:44:44.750

Reputation: 12 197

Answers

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

Posted 2015-12-24T13:44:44.750

Reputation: 18 640

How do I get rid of the "chunkiness" of the plot? It should be much smoother. – orome – 2015-12-25T14:16:03.450

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

Posted 2015-12-24T13:44:44.750

Reputation: 104 223

How you yo get a TARDIS?! – orome – 2015-12-24T14:58:02.713

@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 – 2015-12-24T15:19:00.420

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

Posted 2015-12-24T13:44:44.750

Reputation: 34 072

How do I examine an EventSeries to discover that this is necessary? – orome – 2015-12-24T14:12:08.297

1You 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 – 2015-12-24T14:23:20.707