6
$\begingroup$

I have a problem plotting log with specific binning using the DensityHistogram. The following worked till Mathematica 11 but not anymore with Mathematica 12:

data1 = RandomVariate[BinormalDistribution[{0, 0}, {2, 3}, 0.5], 
   10000];
data2 = RandomVariate[BinormalDistribution[{3, 4}, {2, 2}, .1], 10000];
data = data1~Join~data2;

DensityHistogram[data, {{-15, 15, 0.1}, {-15, 15, 0.1}}, {"Log", 
  "Count"}, ColorFunction -> "TemperatureMap", 
 ChartLegends -> Automatic]

Any idea how to use the DensitiyHistogram with specific binning in xy? Automatic binning works, but it is not useful for my application.

$\endgroup$
1
  • 2
    $\begingroup$ I'm able to reproduce this in comparing 11.3 vs. 12.0 on macOS. Adding bugs tag, it most certainly is. $\endgroup$
    – ktm
    Aug 20, 2019 at 14:44

1 Answer 1

4
$\begingroup$

A work-around: Use (Log[#3]&) instead of {"Log", "Count"} as the height specs:

DensityHistogram[data, {{-15, 15, 0.1}, {-15, 15, 0.1}},  (Log[#3] &), 
 ColorFunction -> "TemperatureMap", 
 PerformanceGoal -> "Speed", ChartLegends -> Automatic, 
 PlotRange -> {{-15, 15}, {-15, 15}, All}]

enter image description here

The issue seems to arise when the number of bins is large. If we change the bin specs to get fewer bins the height spec {"Log", "Count"} works as expected:

DensityHistogram[data, {{-15, 15, 0.5}, {-15, 15, 0.5}}, {"Log", "Count"}, 
 ColorFunction -> "TemperatureMap", 
 ChartLegends -> Automatic, 
 PlotRange -> {{-15, 15}, {-15, 15}, All}]

enter image description here

DensityHistogram[data, {{-10, 10, 0.1}, {-10, 10, 0.1}}, {"Log", "Count"}, 
   ColorFunction -> "TemperatureMap", 
   ChartLegends -> Automatic, PerformanceGoal -> "Speed"]

enter image description here

Note: PerformanceGoal -> "Speed" is added to stay within cloud credit limits for free Wolfram Cloud frontend.

$\endgroup$
1
  • $\begingroup$ Using (Log[#3]&) works as expected, thanks a lot! $\endgroup$
    – Christof
    Aug 21, 2019 at 9:28

Your Answer

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

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