首页 > 解决方案 > 如何在 matplotlib 中生成矩形箱线图?

问题描述

我有以下绘图代码。

threads1 = [0.453,0.453,0.453,0.453,0.450]
threads2 = [0.286,0.287,0.287,0.288,0.226,0.227,0.226,0.227,0.226,0.227]
threads3 = [0.114,0.117,0.346,0.089,0.098,0.347,0.088,0.089,0.275,0.087,0.089,0.275,0.089,0.095,0.277]
threads4 = [0.056,0.057,0.230,0.230,0.042,0.043,0.181,0.230,0.046,0.046,0.183,0.184,0.042,0.043,0.183,0.184,0.046,0.046,0.183,0.183]
threads5 = [0.028,0.029,0.150,0.162,0.229,0.023,0.025,0.122,0.148,0.186,0.022,0.023,0.117,0.124,0.192,0.020,0.025,0.118,0.119,0.185,0.021,0.022,0.120,0.122,0.183]
threads6 = [0.017,0.018,0.098,0.098,0.172,0.177,0.012,0.012,0.083,0.100,0.142,0.145,0.013,0.014,0.076,0.076,0.139,0.138,0.012,0.014,0.082,0.076,0.137,0.145,0.014,0.014,0.077,0.078,0.135,0.139]
threads7 = [0.013,0.014,0.066,0.071,0.127,0.133,0.164,0.010,0.011,0.053,0.067,0.103,0.106,0.131,0.011,0.011,0.052,0.055,0.098,0.101,0.134,0.011,0.011,0.053,0.055,0.102,0.103,0.136,0.011,0.011,0.051,0.056,0.099,0.103,0.135]
threads8 = [0.011,0.011,0.046,0.047,0.096,0.096,0.140,0.147,0.008,0.008,0.047,0.039,0.074,0.077,0.110,0.113,0.008,0.008,0.037,0.039,0.076,0.077,0.112,0.113,0.008,0.008,0.038,0.039,0.075,0.075,0.110,0.112,0.007,0.008,0.035,0.052,0.078,0.078,0.114,0.119]
data = [threads1, threads2, threads3, threads4, threads5, threads6, threads7, threads8]
plt.boxplot(data, numThreads)
plt.ylabel('Time per thread (seconds)')
plt.xlabel('Number of Threads')

产生以下箱线图

在此处输入图像描述

我很困惑为什么它们不是盒子。梯形代表什么?

谢谢!

标签: pythonmatplotlib

解决方案


  • numThreadnotch参数位置中matplotlib.pyplot.boxplot。去掉它。
    • 此参数为False默认值。
    • 缺口代表中位数周围的置信区间 (CI)。
# plot without notch
plt.boxplot(data)
plt.ylabel('Time per thread (seconds)')
plt.xlabel('Number of Threads')

在此处输入图像描述


推荐阅读