在python matplotlib中调整boxplot中框的宽度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32443803/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adjust width of box in boxplot in python matplotlib
提问by user308827
采纳答案by Jiloc
From the documentationthere 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.
宽度:类似数组,默认值 = 0.5
标量或向量并设置每个框的宽度。默认值为 0.5,如果较小,则为 0.15*(极端位置之间的距离)。
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()
回答by Dimitris Fasarakis Hilliard
Try working via the axes
and see if it works:
尝试通过 工作axes
,看看它是否有效:
fig = plt.figure()
ax = fig.add_subplot(111)
ax.boxplot(boxes, widths = 0.6, patch_artist = True)