When you plot a dataset with BoxWhiskerChart passing over the box in the plot with your mouse pointer shows some specifics about the dataset (min and max values, 1/4, 1/2, and 3/4 quartiles). However, if you use Quartiles or Median to calculate those values, they do not correspond. The values displayed by BoxWhiskerChart are different. Does anyone have an explanation or is it simply a bug? Is it system specific (here 8.0.1 on OSX 10.6.8)?

data = RandomVariate[NormalDistribution[0, 1], 20]
  • $\begingroup$ What happens if you try with an odd number of elements? If I remember well, the Median[]definition changes for lists of odd and even lengths. $\endgroup$ Jun 16, 2012 at 17:31
  • $\begingroup$ @belisarius Good point. With an odd number of elements the median is correct, however, the 1/4 and 3/4 quartiles are still wrong. $\endgroup$
    – VLC
    Jun 16, 2012 at 17:35
  • $\begingroup$ @VLC: that would be "different", not "wrong". Mathematica allows for different parameters for Quantile[], as I have indicated in my answer. $\endgroup$ Jun 16, 2012 at 17:46
  • $\begingroup$ @J.M. you're right (or "different"). I wrote my comment just a sec before your answer appeared. $\endgroup$
    – VLC
    Jun 16, 2012 at 17:48

3 Answers 3


What BoxWhiskerChart[] is actually using for the quartiles (and the median as well) is Quantile[data, {1/4, 1/2, 3/4}], or more explicitly, Quantile[data, {1/4, 1/2, 3/4}, {{0, 0}, {1, 0}}] (what the docs calls the "inverse empirical CDF" parameters).

Quartiles[data] (and thus also Median[]), on the other hand, is equivalent to Quantile[data, {1/4, 1/2, 3/4}, {{1/2, 0}, {0, 1}}] ("linear interpolation" parameters); these two different ways to specify the quantiles will almost always give different results for a particular data set.

Unfortunately, there does not seem to be an easy way to let BoxWhiskerChart[] know what parameters you prefer to use for Quantile[].

Brett's answer displays the (not-too-well documented) "BoxRange" suboption for Method; as I mentioned in a comment, the compact way to use that along with whatever quantile definition you prefer is BoxWhiskerChart[data, Method -> {"BoxRange" -> (Quantile[#, Range[0, 1, 1/4], {{1/2, 0}, {0, 1}}] &)}], and you can replace {{1/2, 0}, {0, 1}} with your desired parameter set.

  • 3
    $\begingroup$ With the LabelingFunction Option you could at least show the desired values in the tooltip box $\endgroup$ Jun 16, 2012 at 17:40

There's an Method option, "BoxRange" that can be used to control the calculation of the box parameters:

BoxWhiskerChart[data, GridLines -> {None, Quartiles[data]},
   Method -> {"BoxRange" -> (Flatten[{Min[#], Quartiles[#], Max[#]}] &)}]

box-whisker chart

The first example under Properties & Relations that shows how the various properties of the chart are calculated, using a concrete dataset.

  • 3
    $\begingroup$ Method -> {"BoxRange" -> (Quantile[#, Range[0, 1, 1/4], {{1/2, 0}, {0, 1}}] &)} is a bit more compact... $\endgroup$ Jun 17, 2012 at 4:49
  • $\begingroup$ @brett-champion, Do you know what is happening to the "Outliers" when you change the "BoxRange" method? See this post to see, some outliers are being removed when we use a custom box range. $\endgroup$
    – Jason B.
    Feb 24, 2016 at 11:14

By using J. M.'s answer, this will provide you with a "corrected" tooltip:

label[data_, index_, label_] := 
  Grid[{{Style["max", Bold], 1},           {Style["75%", Bold], #1[[2]]}, 
        {Style["median", Bold], #1[[3]]},  {Style["25%", Bold], #1[[4]]}, 
        {Style["min", Bold], #1[[5]]}}, 
     Dividers -> {{#, #}, {#, #}} &@{Directive[GrayLevel[0.3]], Directive[GrayLevel[0.3]]}, 
     Alignment -> {{Center, ".", {Left}}}, Frame -> GrayLevel[0], 
     BaseStyle -> Directive[AbsoluteThickness[1], Dashing[{}]]] &@
   Join[{Max@data}, Reverse@Quartiles[data], {Min@data}];

data = RandomVariate[NormalDistribution[0, 1], 20]; 

 LabelingFunction -> (Placed[label[##], Tooltip] &), 
 ChartLabels -> Placed[Range[2005, 2009], None]]

box-whisker chart with modified tooltips

  • $\begingroup$ I'd replace Join[{Max@data}, Reverse@Quartiles[data], {Min@data}] with Quantile[data, Range[1, 0, -1/4], {{1/2, 0}, {0, 1}}] myself... $\endgroup$ Jun 17, 2012 at 4:43

Your Answer

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

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