# Using bin values and metadata in ChartElementFunction in histograms

The DensityHistogram command lets you specify a ChartElementFunction which according to the documentation:

The arguments supplied to ChartElementFunction are the bin region {{xmin,xmax},{ymin,ymax}}, the bin values lists, and metadata {m1,m2,...}.

My question is how can I use the bin values lists and the metadata? When I try to access them all I get something like

SystemDensityHistogramDumpthisBinList\$270262

-
I think you're out of luck for the time being. – Brett Champion Oct 23 '12 at 16:36

It doesn't look like the last two parameter sets that the documentation promises are passed to ChartElementFunction are actually passed. A test:

DensityHistogram[RandomVariate[BinormalDistribution[.5], 20],
ChartElementFunction -> Print];


{{-2.,-1.},{-2.,-1.}}{}{}

{{-1.,0.},{-2.,-1.}}{}{}

{{-1.,0.},{-1.,0.}}{}{}

{{-1.,0.},{0.,1.}}{}{}

{{-1.,0.},{1.,2.}}{}{}

{{0.,1.},{-2.,-1.}}{}{}

{{0.,1.},{-1.,0.}}{}{}

{{0.,1.},{0.,1.}}{}{}

{{0.,1.},{1.,2.}}{}{}

{{1.,2.},{2.,3.}}{}{}

{{3.,4.},{1.,2.}}{}{}

The bin lists themselves can be obtained in two ways:

Firstly, from the internals of DensityHistogram using the height specification function (one possibility for the third argument):

data = RandomVariate[BinormalDistribution[.5], 20];

Reap[
DensityHistogram[data, Automatic, ((Sow[{##}, bindata]; ##) &)],
bindata
]


Secondly, using HistogramList:

HistogramList[data]


{{{-2, -1, 0, 1, 2, 3}, {-2, -1, 0, 1, 2}}, {{0, 2, 1, 0}, {1, 0, 3, 0}, {0, 3, 3, 0}, {0, 0, 2, 4}, {0, 0, 1, 0}}}

As you can see, the bin boundary specification is written slightly different, but is in principle the same. The bin count lists are the same.

-