46

Is there any way of hiding the outliers when plotting a boxplot in matplotlib (python)?

I'm using the simplest way of plotting it:

  from pylab import *
  boxplot([1,2,3,4,5,10])
  show()

This gives me the following plot:

(I cannot post the image because I have not enough reputation, but basically it is a boxplot with Q1 at y=1, Q3 at y=5, and the outlier at y=10)

I would like to remove the outlier at y=10, so that the plot only shows from Q1 to Q3 (in this case from 1 to 5).

smci
  • 32,567
  • 20
  • 113
  • 146
Didac Busquets
  • 605
  • 1
  • 5
  • 8

1 Answers1

92

In current versions of matplotlib you can do:

boxplot([1,2,3,4,5,10], showfliers=False)

or

boxplot([1,2,3,4,5,10], sym='')

In older versions, only the second approach will work.

The docs for boxplot do mention this, btw as, "Enter an empty string (‘’) if you don’t want to show fliers.", though, at least for myself, "outliers" is the more familiar word.

tom10
  • 67,082
  • 10
  • 127
  • 137
  • That definitely does it. My fault... didn't read the doc carefully (just looked for outlier, not for flier!). – Didac Busquets Feb 25 '14 at 23:37
  • No problem, and it would be hard to find in the docs if you didn't know it already -- I had the advantage of going to other way. (I'll edit my answer to sound like was less obvious, since it wasn't particularly clear.) – tom10 Feb 25 '14 at 23:51
  • 2
    @DidacBusquets Just want to chime in here and say that in v1.4, you'll be able to pass a `showfliers=False` option when you call boxplot. – Paul H Feb 25 '14 at 23:57
  • @Paul H: please feel free to edit my answer when this becomes readily available. – tom10 Feb 26 '14 at 22:20
  • In matplotlib 1.2 outliers are hidden with `boxplot(data,0,'')`. See (http://matplotlib.org/1.2.1/api/pyplot_api.html) – MasterControlProgram Feb 03 '17 at 12:08