Seaborn Boxplot Quartile Calculation
i am using seaborn version 0.7.1 for python. I am trying to create a boxplot for the below numpy array arr = np.array([2, 4, 5, 5, 8, 8, 9]) from my understanding the Quartiles Q1
Solution 1:
It would of course depend on the definition of a quartile.
Wikipedia mentions 3 methods to calculate the quartile,
- method1: Take median of the lower part of the sample [2,4,5]. Result 4.
- method2: Take median of the lower part of the sample (including its median) [2,4,5,5]. Result 4.5.
- method3: The lower quartile is 75% of the second data value plus 25% of the third data value. Result: 4*0.75+5*0.25 = 4.25. (It's always the mean between method1 and 2.
You may also use numpy to calculate the quartiles
x = [2, 4, 5, 5, 8, 8, 9]
np.percentile(x, [25])
This returns 4.5
Post a Comment for "Seaborn Boxplot Quartile Calculation"