Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
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

share|improve this question
Please try to post self contained code. Add one more statement to fill your data – Dr. belisarius Jan 17 '13 at 21:09
Yes, please include code to fill data so this can be run and observed without additional effort. – Mr.Wizard Mar 31 '13 at 0:00
fixed it so that it is :) – AimForClarity Apr 1 '13 at 19:46
I cannot reproduce this error in version 8.0.0. – whuber Apr 1 '13 at 21:56
I definetly get it on x64 – AimForClarity Apr 1 '13 at 23:39

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

share|improve this answer
Is this a bug then? – Mike Honeychurch Jan 17 '13 at 23:52
@MikeHoneychurch - I guess so. – Verbeia Jan 17 '13 at 23:58
Maybe if someone like @BrettChampion can confirm then it can be tagged as a bug. – Mike Honeychurch Jan 18 '13 at 0:09
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. – AimForClarity Jan 18 '13 at 0:31
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 – AimForClarity Jan 18 '13 at 5:04
up vote 0 down vote accepted

Thanks to Jesus from Mathematica, here are two workarounds:


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


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]}]
share|improve this answer

Your Answer


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.