Adjust window width in boxplot in python matplotlib

I would like to reduce the width of the boxes in the square box below. Here is my code, but it does not work:

bp = plt.boxplot(boxes, widths = 0.6, patch_artist = True)

enter image description here

+4
source share
2 answers

The documentation has a width option:

widths: array-like, default = 0.5

It is either a scalar or a vector and sets the width of each window. The default value is 0.5 or 0.15 * (the distance between the extreme positions), if it is less.

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

Result

+10
source

Try working through axesand see if it works:

fig = plt.figure()
ax = fig.add_subplot(111)
ax.boxplot(boxes, widths = 0.6, patch_artist = True)
+1
source

Source: https://habr.com/ru/post/1606299/


All Articles