Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly do the whiskers in pandas' boxplots specify?

Tags:

pandas

boxplot

In python-pandas boxplots with default settings, the red bar is the mean median, and the box signifies the 25th and 75th quartiles, but what exactly do the whiskers mean in this case? Where is the documentation to figure out the exact definition (couldn't find it)?

Example code:

df.boxplot()

Example result:

enter image description here

like image 865
vasek1 Avatar asked Aug 22 '12 23:08

vasek1


People also ask

What do whiskers in Boxplot represent?

Description. A Box and Whisker Plot (or Box Plot) is a convenient way of visually displaying the data distribution through their quartiles. The lines extending parallel from the boxes are known as the “whiskers”, which are used to indicate variability outside the upper and lower quartiles.

What does the length of the whiskers in a regular box plot tell you?

The box in the box plot will show the median and the first and third quartiles. The length of the upper whisker is the largest value that is no greater than the third quartile plus 1.5 times the interquartile range.

What is whisker plot in Python?

A Box Plot is also known as Whisker plot is created to display the summary of the set of data values having properties like minimum, first quartile, median, third quartile and maximum.


2 Answers

Pandas just wraps the boxplot function from matplotlib. The matplotlib docs have the definition of the whiskers in detail:

whis : float, sequence, or string (default = 1.5)

As a float, determines the reach of the whiskers to the beyond the first and third quartiles. In other words, where IQR is the interquartile range (Q3-Q1), the upper whisker will extend to last datum less than Q3 + whis*IQR). Similarly, the lower whisker will extend to the first datum greater than Q1 - whis*IQR. Beyond the whiskers, data are considered outliers and are plotted as individual points.

Matplotlib (and Pandas) also gives you a lot of options to change this default definition of the whiskers:

Set this to an unreasonably high value to force the whiskers to show the min and max values. Alternatively, set this to an ascending sequence of percentile (e.g., [5, 95]) to set the whiskers at specific percentiles of the data. Finally, whis can be the string 'range' to force the whiskers to the min and max of the data.

Below a graphic that illustrates this from a stats.stackexchange answer. Note that k=1.5 if you don't supply the whis keyword in Pandas.

enter image description here

like image 158
Joooeey Avatar answered Nov 30 '22 23:11

Joooeey


You mention in your question that the red line is the mean - it is actually the median.

From the matplotlib link mentioned by Chang She above:

The box extends from the lower to upper quartile values of the data, with a line at the median. The whiskers extend from the box to show the range of the data. Flier points are those past the end of the whiskers.

I didn't experiment, but there is a 'meanline' option which might put the line at the mean.

like image 36
TimCera Avatar answered Dec 01 '22 01:12

TimCera