Reputation: 21961
I would like to reduce the width of the boxes in the boxplot below. Here's my code, but it is not working:
bp = plt.boxplot(boxes, widths = 0.6, patch_artist = True)
Upvotes: 13
Views: 72989
Reputation: 3658
From the documentation there is a widths option:
widths : array-like, default = 0.5
Either a scalar or a vector and sets the width of each box. The default is 0.5, or 0.15*(distance between extreme positions) if that is smaller.
Here is an example:
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(937)
data = np.random.lognormal(size=(37, 4), mean=1.5, sigma=1.75)
labels = list('ABCD')
fs = 10 # fontsize
plt.boxplot(data, labels=labels, showfliers=False, widths=(1, 0.5, 1.2, 0.1))
plt.show()
Upvotes: 24
Reputation: 160417
Try working via the axes
and see if it works:
fig = plt.figure()
ax = fig.add_subplot(111)
ax.boxplot(boxes, widths = 0.6, patch_artist = True)
Upvotes: 4