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)
The length of the box becomes its height. The width across the page signifies nothing. Much more can be read from a boxplot than might be surmised from the simplistic method of its construction, particularly when the boxplots of several samples are lined up alongside one another (Parallel Boxplots).
The widths of the box plot indicate the size of the samples. The wider the box, the larger the sample. This is usually an option in statistical software programs, not all Box Plots have the widths proportional to the sample size.
conf_intervals : This parameter is also an array or sequence whose first dimension is compatible with x and whose second dimension is 2. positions : This parameter is used to sets the positions of the boxes.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With