Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get min and max values from boxplot in python? [duplicate]

In python:

fig1, ax1 = plt.subplots()
ax1.set_title('Basic Plot')
ax1.boxplot(data)

The IQR can be calculated with:

IQR = stats.iqr(data, interpolation = 'midpoint')

How would I obtain the min and max values "The Whiskers" for each box blot?

like image 766
wwjdm Avatar asked Apr 08 '26 04:04

wwjdm


1 Answers

Dataframe has the quantile function:

Q1 = df["COLUMN_NAME"].quantile(0.25)

Q3 = df["COLUMN_NAME"].quantile(0.75)

IQR = Q3 - Q1

Lower_Fence = Q1 - (1.5 * IQR)

Upper_Fence = Q3 + (1.5 * IQR)

Thus you would have to get the first value less than the fence value

def iqr_fence(x):
    Q1 = x.quantile(0.25)
    Q3 = x.quantile(0.75)
    IQR = Q3 - Q1
    Lower_Fence = Q1 - (1.5 * IQR)
    Upper_Fence = Q3 + (1.5 * IQR)
    u = max(x[x<Upper_Fence])
    l = min(x[x>Lower_Fence])
    return [u,l]
like image 159
wwjdm Avatar answered Apr 09 '26 17:04

wwjdm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!