2

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?

Daniel Walker
  • 6,380
  • 5
  • 22
  • 45
wwjdm
  • 2,568
  • 7
  • 32
  • 61
  • Look at the return value of `ax1.boxplot(...)`. It is a dictionary of matplotlib objects, which you can ask for their properties. – Niklas Mertsch Jun 11 '20 at 18:15
  • 2
    This question is a duplicate of [Obtaining values used in boxplot, using python and matplotlib](https://stackoverflow.com/questions/23461713/obtaining-values-used-in-boxplot-using-python-and-matplotlib) and should be closed. If your answer is distinctive from those offered, it should be added to the duplicate question. – Trenton McKinney Jun 11 '20 at 19:49

1 Answers1

8

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]
wwjdm
  • 2,568
  • 7
  • 32
  • 61