Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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
share|improve this question
1  
I think you're out of luck for the time being. –  Brett Champion Oct 23 '12 at 16:36

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.