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.

Is there an easy (recommended) way to align regular plots (e.g. ListPlot or Plot) with chart type graphics (BarChart or DistributionChart)?

For example:

Show[
   DistributionChart[Table[RandomReal[NormalDistribution[i, .2], 1000], {i, 1, 10}]], 
   ListPlot[Range[1, 10]]
]

Not aligned!

I would like the points of the ListPlot to reside exactly on top of the DistributionChart elements. Furthermore, the coordinate positioning of chart elements seems to vary with the number of elements (which is ridiculous).

Show[
    DistributionChart[Table[RandomReal[NormalDistribution[i, .2], 1000], {i, 1, 3}]], 
    ListPlot[Range[1, 3]]
]

Not aligned 2

share|improve this question
1  
Are you sure you aren't doing something different? This is what I get (and a similar correct figure for the second case). Try doing it in a fresh kernel (and without custom options, if any) –  rm -rf Jul 9 '12 at 19:18
    
@R.M I get the same as the OP. Version mismatch? –  belisarius Jul 9 '12 at 19:22
    
I get the same output as @R.M (v 8.0.4.0 Windows Vista 64 bit) –  kguler Jul 9 '12 at 19:25
    
No, fresh kernel doesn't help. I plotted the diagrams with Mathematica 8.0.0.0 on Mac OS X 10.7. Tried it on Windows with the same Mathematica version and get the same result. Which version are you using @R.M ? –  phantomas1234 Jul 9 '12 at 19:27
    
I get the same as R.M with Mathematica 8.0.4 for OS X. –  Heike Jul 9 '12 at 19:40
show 1 more comment

1 Answer 1

up vote 7 down vote accepted

Seems it is a problem localized to version 8.0.0. Here is a way to fix it by scaling your ListPlot using the FrameTicks of the DistributionChart.

k = DistributionChart[Table[RandomReal[NormalDistribution[i, .2], 100], {i, 1, 20}], 
         Method -> {"BoxWidth" -> "Fixed"}]; 
l = (Sort@((FrameTicks /. Options[k, "FrameTicks"])[[2, 1, All, 1]]))[[2 ;; -2]];
f = Interpolation[Transpose[{Range@Length@l, l}]];
Show[k, ListPlot[Table[{f@i, i}, {i, 15}], PlotStyle -> Directive[Red, PointSize[Large]]]]

enter image description here

share|improve this answer
add comment

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.