3
$\begingroup$
data = RandomReal[NormalDistribution[0.5, 0.1], {10000, 2}];
DensityHistogram[data, PlotRange -> 1, Method -> {"DistributionAxes" -> "Histogram"}]

The problem I have is that the histogram on the axes is not aligned with the density plot because of the PlotRange. I tried using Mathematica 8 and 9. Can someone please help me fix this?

Problem Graph

$\endgroup$
5
  • 2
    $\begingroup$ Please try to post self contained code. Add one more statement to fill your data $\endgroup$ Commented Jan 17, 2013 at 21:09
  • $\begingroup$ Yes, please include code to fill data so this can be run and observed without additional effort. $\endgroup$
    – Mr.Wizard
    Commented Mar 31, 2013 at 0:00
  • $\begingroup$ fixed it so that it is :) $\endgroup$ Commented Apr 1, 2013 at 19:46
  • $\begingroup$ I cannot reproduce this error in version 8.0.0. $\endgroup$
    – whuber
    Commented Apr 1, 2013 at 21:56
  • $\begingroup$ I definetly get it on 8.0.1.0 x64 $\endgroup$ Commented Apr 1, 2013 at 23:39

2 Answers 2

5
$\begingroup$

This issue also arises in version 9. Possible workarounds include:

a) Removing the PlotRange option and letting Mathematica choose the plot range automatically.

data = RandomVariate[MultinormalDistribution[{0.001, 
     0.001}, {{0.005, 0.0015}, {0.0015, 0.0040}}], {1000}];

DensityHistogram[data, Method -> {"DistributionAxes" -> "Histogram"}, 
 ImageSize -> 250]

enter image description here

b) Using one of the other options for distribution axes, which do not suffer from this problem.

 DensityHistogram[data, PlotRange -> 0.35, 
 Method -> {"DistributionAxes" -> "BoxWhisker"}, ImageSize -> 250]

enter image description here

DensityHistogram[data, PlotRange -> 0.35, 
 Method -> {"DistributionAxes" -> True}, ImageSize -> 250]

enter image description here

$\endgroup$
5
  • $\begingroup$ Is this a bug then? $\endgroup$ Commented Jan 17, 2013 at 23:52
  • $\begingroup$ @MikeHoneychurch - I guess so. $\endgroup$
    – Verbeia
    Commented Jan 17, 2013 at 23:58
  • 1
    $\begingroup$ Maybe if someone like @BrettChampion can confirm then it can be tagged as a bug. $\endgroup$ Commented Jan 18, 2013 at 0:09
  • $\begingroup$ Thank you, but the thing is that I need the histogram on the axrs and I need the Plot Range. I think it must be a bug. $\endgroup$ Commented Jan 18, 2013 at 0:31
  • $\begingroup$ I should point out that I really also want the whole distribution to be in its right place, ie the gaussian blob should have an offset it should NOT be centered on (0,0), but mathematica seems to recenter it after DensityHistogram. any thoughts on how I can move it? maybe using show $\endgroup$ Commented Jan 18, 2013 at 5:04
0
$\begingroup$

Thanks to Jesus from Mathematica, here are two workarounds:

data=RandomReal[NormalDistribution[0.5,0.1],{10000,2}];

Show[DensityHistogram[data, Method -> {"DistributionAxes" -> "Histogram"}], PlotRange -> 1]

or

ReplaceAll[DensityHistogram[data,PlotRange->1,Method->{"DistributionAxes"->"Histogram"}, PerformanceGoal->"Speed"],{Inset[obj_,{x_,y_},{Left,Top},off_]:>Inset[obj,{Min[data[[All,1]]],y},{Left,Top},off],Inset[obj_,{x_,y_},{Right,Bottom},off_]:>Inset[obj,{x,Min[data[[All,2]]]},{Right,Bottom},off]}]
$\endgroup$

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.