I am trying to draw a custom BoxWhiskerChart with alternative values determining fences. I have data that has a lot of outliers and I have to compare it to another chart that has 10-90th percentile instead of standard min/max.

How would I go about it?

  • $\begingroup$ Hi ! Do you have any code you can share with us ? $\endgroup$
    – Sektor
    Jul 16 '14 at 21:59
  • 1
    $\begingroup$ Hi,data = RandomVariate[NormalDistribution[0, 1], 200]; BoxWhiskerChart[data] is the function I am using. Nothing more fancy about it. I am wondering if there is a way to modify the specification of what is a fence - ie instead of min-max - I would like it to be 10-th and 90th percentile. $\endgroup$
    – jps
    Jul 16 '14 at 22:07
  • $\begingroup$ I would imagine it is possible to draw boxes, I am not sure how to use mathematica function draw[] to plot fences. $\endgroup$
    – jps
    Jul 16 '14 at 22:10

With the data beeing

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

the range of the box specified to be one sigma (approx. 68.3 %tile range) by


and a limit for the fences defined to be 10 %

fencesLimit = 0.1

we can plot a BoxWhiskerChart using:

BoxWhiskerChart[data, "Median", 
 Method -> 
  "BoxRange" -> 
   (Quantile[#, {fencesLimit, (1 - sigma)/2, 1/2, (1 + sigma)/2, 1 - fencesLimit}, 
      {{1/3, 1/3}, {0, 1}}] &)]

This BoxWhisker is median centered, has a box range of one sigma, a lower fence at the 10 percentile, and an upper fence at the 90 percentile.
You can find in the documentation of Quantile how to choose another centering.

Here a plot of this BoxWhiskerChart:


With some additional styling and as a function with optional arguments:

bwChart[data_, br_: Erf[1/Sqrt[2]], flimit_: 0.1] := 
   {{"MedianMarker", 1, Directive[Thickness[0.01], Blue]}, {"MedianNotch", 0.5, Gray}},
   Method -> "BoxRange" -> (Quantile[#, {flimit, (1 - br)/2, 1/2, (1 + br)/2, 1 - flimit}, 
     {{1/3, 1/3}, {0, 1}}] &), 
   BarSpacing -> None, AspectRatio -> 0.7, BarOrigin -> Left, 
   ChartElementFunction -> "GlassBoxWhisker", ChartStyle -> 6]



Using Mathematica version 11.0.0 the output of bwChart[data] is


A direct comparison of the same data as a 10th to 90th %tile BoxWhiskerChart with an "Outliers" and a standard min/max BoxWhiskerChart.

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

  BoxWhiskerChart[{data, Null, Null}, "Outliers", 
   Method -> 
    {"BoxRange" -> (Quantile[#, {10/100, 1/4, 1/2, 3/4, 90/100}, {{1/2, 0}, {0, 1}}] &)}], 
  BoxWhiskerChart[{Null, data, Null}, "Outliers"],
  BoxWhiskerChart[{Null, Null, data}]


  • $\begingroup$ (+1) Thank you! Spent hours to make BoxRange work as an option :) $\endgroup$
    – kglr
    Jul 17 '14 at 2:08
  • 1
    $\begingroup$ @Masi Did you use bwChart[data] to produce the output? It wasn't part of the posted code block before my latest edit, which also shows the output I get using version 11. If you are still having problems, please be more specific of what you cannot reproduce. $\endgroup$
    – Karsten 7.
    Sep 27 '16 at 11:08
  • 1
    $\begingroup$ @Masi For me replacing data with {data1, data2} does produce the expected output. Here is a screen snipped of the in- and output I used to test it. Did I misunderstand you or does that solve your problem? (I'm not sure what you mean with "with other data sources in the same figure".) $\endgroup$
    – Karsten 7.
    Sep 27 '16 at 14:00
  • 1
    $\begingroup$ @Masi Please see my edit. I'd use Show to combine these different kinds of BoxWhiskerCharts into one graph. $\endgroup$
    – Karsten 7.
    Sep 27 '16 at 15:56
  • 1
    $\begingroup$ @Masi If your data doesn't have any outliers, then that is expected. Also having very few data points can result in all BoxWhiskerCharts looking the same. Here is one example. The relatively big boxes in your image certainly makes it look like you don't have a lot of data point and that they are relative uniformly distributed. $\endgroup$
    – Karsten 7.
    Sep 27 '16 at 17:41

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.