Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib boxplot without outliers

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).

like image 823
Didac Busquets Avatar asked Feb 25 '14 22:02

Didac Busquets


People also ask

How do I create a boxplot in Matplotlib?

Creating Box Plotpyplot module of matplotlib library provides boxplot() function with the help of which we can create box plots. The data values given to the ax. boxplot() method can be a Numpy array or Python list or Tuple of arrays. Let us create the box plot by using numpy.


1 Answers

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.

like image 197
tom10 Avatar answered Oct 11 '22 22:10

tom10