Carpetfizz
Carpetfizz

Reputation: 9149

How to generate rectangular boxplots in matplotlib?

I have the following plotting code.

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')

which produces the following box plot

enter image description here

I'm confused why they are not boxes. What do the trapezoidal shapes represent?

Thanks!

Upvotes: 0

Views: 144

Answers (1)

Trenton McKinney
Trenton McKinney

Reputation: 62383

  • numThread is in the notch parameter location in matplotlib.pyplot.boxplot. Remove it.
    • This parameter is False by default.
    • The notches represent the confidence interval (CI) around the median.
# plot without notch
plt.boxplot(data)
plt.ylabel('Time per thread (seconds)')
plt.xlabel('Number of Threads')

enter image description here

Upvotes: 1

Related Questions