@@ -1860,12 +1860,17 @@ def boxplot_stats(X, whis=1.5, bootstrap=None, labels=None):
1860
1860
Data that will be represented in the boxplots. Should have 2 or fewer
1861
1861
dimensions.
1862
1862
1863
- whis : float (default = 1.5)
1864
- Determines the reach of the whiskers past the first and third
1865
- quartiles (e.g., Q3 + whis*IQR). Beyond the whiskers, data are
1866
- considers outliers and are plotted as individual points. Set
1867
- this to an unreasonably high value to force the whiskers to
1868
- show the min and max data. (IQR = interquartile range, Q3-Q1)
1863
+ whis : float, string, or sequence (default = 1.5)
1864
+ As a float, determines the reach of the whiskers past the first and
1865
+ third quartiles (e.g., Q3 + whis*IQR). Beyond the whiskers, data are
1866
+ considers outliers and are plotted as individual points. Set this
1867
+ to an unreasonably high value to force the whiskers to show the min
1868
+ and max data. (IQR = interquartile range, Q3-Q1). Alternatively, set
1869
+ this to an ascending sequence of percentile (e.g., [5, 95]) to set
1870
+ the whiskers at specific percentiles of the data. Finally, can be the
1871
+ string 'range' to force the whiskers to the min and max of the data.
1872
+ In the edge case that the 25th and 75th percentiles are equivalent,
1873
+ `whis` will be automatically set to 'range'
1869
1874
1870
1875
bootstrap : int or None (default)
1871
1876
Number of times the confidence intervals around the median should
@@ -1968,22 +1973,38 @@ def _compute_conf_interval(data, med, iqr, bootstrap):
1968
1973
1969
1974
# interquartile range
1970
1975
stats ['iqr' ] = stats ['q3' ] - stats ['q1' ]
1976
+ if stats ['iqr' ] == 0 :
1977
+ whis = 'range'
1971
1978
1972
1979
# conf. interval around median
1973
1980
stats ['cilo' ], stats ['cihi' ] = _compute_conf_interval (
1974
1981
x , stats ['med' ], stats ['iqr' ], bootstrap
1975
1982
)
1976
1983
1977
- # highest non-outliers
1978
- hival = stats ['q3' ] + whis * stats ['iqr' ]
1984
+ # lowest/highest non-outliers
1985
+ if np .isscalar (whis ):
1986
+ if np .isreal (whis ):
1987
+ loval = stats ['q1' ] - whis * stats ['iqr' ]
1988
+ hival = stats ['q3' ] + whis * stats ['iqr' ]
1989
+ elif whis in ['range' , 'limit' , 'limits' , 'min/max' ]:
1990
+ loval = np .min (x )
1991
+ hival = np .max (x )
1992
+ else :
1993
+ whismsg = 'whis must be a float, valid string, or ' \
1994
+ 'list of percentiles'
1995
+ raise ValueError (whismsg )
1996
+ else :
1997
+ loval = np .percentile (x , whis [0 ])
1998
+ hival = np .percentile (x , whis [1 ])
1999
+
2000
+ # get high extreme
1979
2001
wiskhi = np .compress (x <= hival , x )
1980
2002
if len (wiskhi ) == 0 or np .max (wiskhi ) < stats ['q3' ]:
1981
2003
stats ['whishi' ] = stats ['q3' ]
1982
2004
else :
1983
2005
stats ['whishi' ] = max (wiskhi )
1984
2006
1985
2007
# get low extreme
1986
- loval = stats ['q1' ] - whis * stats ['iqr' ]
1987
2008
wisklo = np .compress (x >= loval , x )
1988
2009
if len (wisklo ) == 0 or np .min (wisklo ) > stats ['q1' ]:
1989
2010
stats ['whislo' ] = stats ['q1' ]
0 commit comments