(* SUMMARY - In a Dataset holding DateList entries, how do I extract a minimum and maximum DateList value to pass into DateListPlot's PlotRange specification? See QUESTION further below *)

(* Sample dataset. Actual dataset is much larger. My goal is to create a time series animation where the PlotRange has fixed dimensions for the X/Y axis *)

aDataSet =Dataset[{
<|"aDate"-> { 2015,4,3,2,36,"24." },"aDuration"->5|>,
<|"aDate"-> { 2014,3,2,1,36,"24." },"aDuration"->4|>,
<|"aDate"-> { 2013,2,2,0,36,"24." },"aDuration"->3|>

(* PlotRange for aData *)

dateRange=Sort[aDataSet[[All,"aDate"]]]/@ {First,Last};

(* PlotRange for duration *)

durationRange = Sort[aDataSet[[All,"aDuration"]]]/@ {First,Last};

(* QUESTION - how should I compute dateRange such that it is a form that can be used in PlotRange for DateListPlot? Otherwise, the following will fail because the computed form of dateRange is a Dataset. DateListPlot is expecting a List whose values are the min and maximum dates for the x-axis *)

DateListPlot[aDataSet[[All,{"aDate", "aDuration"}]],Joined->False,
  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$ – bbgodfrey Apr 6 '15 at 1:21
  • $\begingroup$ Thank you for taking a moment to re-formatting my inquiry to improve its readability! $\endgroup$ – A Chase Turner Apr 6 '15 at 11:39

I think your running into trouble with those "24." as the last entry in your date list. That should be a number instead of a string.

aDataSet =Dataset[{
 <|"aDate"-> { 2015,4,3,2,36,24.},"aDuration"->5|>,
 <|"aDate"-> { 2014,3,2,1,36,24.},"aDuration"->4|>,
 <|"aDate"-> { 2013,2,2,0,36,24.},"aDuration"->3|>

With it as a number then the following would work.

aDataSet[All, "aDate", DateObject][{Max, Min}] // Normal

It gets All of the "aDate" values and converts them into DateObjects. The gets the Min and Max and takes it out of the dataset and into a regular list.

Hope this helps.

  • $\begingroup$ BINGO -- Thank you for catching the data typo ... but more importantly, your sample code here answered my issue -- thank you! $\endgroup$ – A Chase Turner Apr 6 '15 at 11:41
  • $\begingroup$ @AChaseTurner you can also use MinMax instead of {Min, Max}, if you have 10.1. $\endgroup$ – Taliesin Beynon Apr 7 '15 at 21:42
  • $\begingroup$ Thank you -- I am using 10.1 and MinMax works for me! $\endgroup$ – A Chase Turner Apr 8 '15 at 23:57

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.