python - 为什么 matplotlib 的缺口箱线图会自行折叠?

标签 python matplotlib

我尝试使用 matplotlib 制作带缺口的箱线图,但发现带缺口的箱子往往会过度延伸然后自行折回。当我制作常规箱线图时,不会发生这种情况。

这可以通过以下代码和生成的结果图看出:

import matplotlib.pyplot as plt

data = [[-0.056, -0.037, 0.010, 0.077, 0.082],
        [-0.014, 0.021, 0.051, 0.073, 0.079]]

# Set 2 plots with vertical layout (1 on top of other)
fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True)

ax1.boxplot(data, 1) #Notched boxplot
ax2.boxplot(data, 0) #Standard boxplot

ax1.set_ylim([-0.1, 0.1])
ax2.set_ylim([-0.1, 0.1])

plt.show()

Bad Notched Boxplot and Std. boxplot

有谁知道我做错了什么以及我该如何解决这个问题?

最佳答案

这意味着数据的分布是倾斜的。 如果两个框的缺口不重叠,则有 95% 的置信度表明它们的中位数不同。

Notch 显示围绕中位数的置信区间,通常基于:enter image description here

enter image description here

也许,您可以更改 bootstrap boxplot 的参数以收紧中位数的置信区间。

请注意,显示图像中上下 mustache 的标签不正确。他们应该分别读作“第 75 个百分位的较小者 + 1.5IQR 或最大值”和“第 25 个百分位的较大者 - 1.5 个 IQR 或最小值”。

关于python - 为什么 matplotlib 的缺口箱线图会自行折叠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38794406/

相关文章:

python - Flask URL路由编码问题

python - 将 JSON 数组转换为 Python 列表

python - Jupyter笔记本: Register mouse position clicks (moves) on a displayed image (jpg/png)

python - matplotlib,如何在给定条件下绘制 3d 2 变量函数

Python pptx - 单元格中具有不同颜色的部分文本

python - 使用 str.endswith() 进行条件检查

Python:包问题

python - 使用 **kwds 时避免 pandas 改变绘图颜色

python - 如何将 matplotlib (python) 窗口保留在后台?

python - matplotlib.pyplot : add horizontal line to sub-plot