8
$\begingroup$

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

$\endgroup$
  • 1
    $\begingroup$ 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) $\endgroup$ – rm -rf Jul 9 '12 at 19:18
  • $\begingroup$ @R.M I get the same as the OP. Version mismatch? $\endgroup$ – Dr. belisarius Jul 9 '12 at 19:22
  • $\begingroup$ I get the same output as @R.M (v 8.0.4.0 Windows Vista 64 bit) $\endgroup$ – kglr Jul 9 '12 at 19:25
  • $\begingroup$ 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 ? $\endgroup$ – phantomas1234 Jul 9 '12 at 19:27
  • $\begingroup$ I get the same as R.M with Mathematica 8.0.4 for OS X. $\endgroup$ – Heike Jul 9 '12 at 19:40
7
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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