2
$\begingroup$

I have the following problem: I need to rescale the counts given to DensityHistogram, meaning that I want to multiply the total counts per bin by a certain number (4/3).

Consider the following example:

datatest = 
  {{0.15853231238493146`, 0.15958921935208797`}, 
   {0.16003302074891018`, 0.1666286356975967`}, 
   {0.15809478105039676`, 0.1682255807995838`}, 
   {0.15548049076146467`, 0.16773090763023435`}, 
   {0.15373202818516943`, 0.16951942019717853`}, 
   {0.15183606682822046`, 0.17098377258873423`}, 
   {0.14965773201820615`, 0.17326285096337588`}, 
   {0.14869661374136575`, 0.17472879297110966`}, 
   {0.17699943466842`, 0.14614660535485596`}}  

DensityHistogram[datatest, {0.01}, ChartLegends -> Automatic]

enter image description here

Because the total counts per bin for all bins would be multiplied with 4/3 and rounded afterwards, the bin in the upper left of this example would become 2.6666 and rounded to 3).

Does anyone have a solution for this? Manually changing the legend is not an option for me, since the legend would the look awkward.

My approach would be to manipulate the HistogramList:

rescalingfactor = 4/3;  
histogramlist1 = HistogramList[datatest, {0.01}];  
histogramlist1rescaled = 
  Join[histogramlist1[[1]], Round[histogramlist1[[2]]*rescalingfactor]]
{{0.14, 0.15, 0.16, 0.17, 0.18}, {0.14, 0.15, 0.16, 0.17, 0.18}, 
 {0, 0, 0, 3}, {0, 1, 4, 1}, {0, 0, 1, 0}, {1, 0, 0, 0}}

But how can I apply DensityHistogram to the results returned from HistogramList?

$\endgroup$

1 Answer 1

2
$\begingroup$

You can use the third argument (height spec) of DensityHistogram

enter image description here

DensityHistogram[datatest, {0.01}, Round[#3*rescalingfactor] &, 
 ChartLegends -> Automatic]

enter image description here

Note: how can I apply DensityHistogram to the results returned from HistogramList?

You can use Round[histogramlist1[[2]]*rescalingfactor] & instead of Round[#3*rescalingfactor] & to get the same result.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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