rrkk
rrkk

Reputation: 469

strange shape of the boxplot using matplotlib

data= np.array([9,13,10,9,13,5,13,9,7,9,13,11])
fig9, ax9 = plt.subplots()
ax9.boxplot(data, notch=True)

I got the strange the notched boxplot. I want to use the notch to highlight the median. Why this figure showed the strange shape? Is this not strange?

enter image description here

I use MacOS 10.14.5 and python 3.7.2.

Upvotes: 5

Views: 606

Answers (1)

Jakob Guldberg Aaes
Jakob Guldberg Aaes

Reputation: 844

It's explained quite clearly in the boxplot documentation. The note states:

Note: In cases where the values of the CI are less than the lower quartile or greater than the upper quartile, the notches will extend beyond the box, giving it a distinctive "flipped" appearance. This is expected behavior and consistent with other statistical visualization packages.

So if you calculate the params you will see that you are en the described case.

>>> [np.quantile(data, i) for i in np.arange(0.25, 1, 0.25)]
[9.0, 9.5, 13.0]
>>> scipy.stats as st
>>> st.t.interval(0.95, len(data)-1, loc=np.mean(data), scale=st.sem(data))
(8.425200299187184, 11.741466367479484)

Upvotes: 5

Related Questions