What exactly do the whiskers in pandas' boxplots specify?

試著忘記壹切 提交于 2020-06-22 11:18:08

问题


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


回答1:


These are specified in the matplotlib documentation. The whiskers are some multiple (1.5 by default) of the interquartile range.




回答2:


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.




回答3:


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.




回答4:


From Amelio Vazquez-Reina's answer in Boxplots in matplotlib: Markers and outliers:

enter image description here

The outliers (the + markers in the boxplot) are simply points outside of the wide [(Q1-1.5 IQR), (Q3+1.5 IQR)] margin below.

FYI: Confused by location of fences in box-whisker plots



来源:https://stackoverflow.com/questions/12082568/what-exactly-do-the-whiskers-in-pandas-boxplots-specify

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!