3
$\begingroup$

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

System`DensityHistogramDump`thisBinList$270262
$\endgroup$
  • 1
    $\begingroup$ I think you're out of luck for the time being. $\endgroup$ – Brett Champion Oct 23 '12 at 16:36
3
$\begingroup$

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
]

Mathematica graphics

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.

$\endgroup$

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.