11

HistogramList and Histogram are closely related:

data = RandomVariate[NormalDistribution[], 200];
bSpec = {1};

{
 BarChart[Last[HistogramList[data, bSpec]]], 
 Histogram[data, bSpec]
}

enter image description here

DateHistogram is more like a black box with respect to that:

dates = AbsoluteTime /@  RandomChoice[DateRange[{2010, 1, 1}, {2010, 5, 31}, "Day"], 200];
 bSpec = "Month";


{
 BarChart[Last[HistogramList[dates, bSpec]]], 
 DateHistogram[dates, bSpec]
}

enter image description here

One could do

Reap[DateHistogram[dates, "Month", (Sow[{##}]; #2) &]][[2, 1, 1]]
 {{{3471292800, 3473971200}, {3473971200, 3476390400}, {3476390400, 

3479068800}, {3479068800, 3481660800}, {3481660800, 3484339200}}, {29, 29, 42, 47, 53}}

BarChart @ Last @ %

enter image description here

And tweak it but it is not pretty/efficient.

Question

Is there a better way to get HistogramList for dates based data? Compatible with DateHistogram?

Kuba
  • 136,707
  • 13
  • 279
  • 740
  • "Month" is not a valid bin specification for HistogramList so you are getting the Automatic setting. You would need to create a bin function that would give a date (maybe AbsoluteTime) partition of the dates for HistogramList. – Edmund Aug 10 '16 at 21:09
  • @Edmund The point is I don't want to because this is already done. DateHistogram uses it. Would be also nice to know what Month means. – Kuba Aug 10 '16 at 21:13

1 Answers1

7
dates = AbsoluteTime /@  RandomChoice[DateRange[{2010, 1, 1}, {2010, 5, 31}, "Day"], 200];
bSpec = "Month";

Didn't have time to dig deeper so it may be limited but it suits my needs atm.

Keep in mind that it is an undocumented function:

binSpec = System`TimeVisualizationsDump`dateHistogramBinning[
  dates,
  bSpec,
  Identity, (*smoothing function - at least the pattern name says so*)
  $TimeZone
  ]

hlist = HistogramList[dates, binSpec ];

{
  BarChart[
     #2, ChartLabels -> (DateString[#, "MonthNameShort"] & /@ #)
  ] & @@  hlist
  ,
  DateHistogram[dates, bSpec]
}

enter image description here

Kuba
  • 136,707
  • 13
  • 279
  • 740