gpt4 book ai didi

python - 在python matplotlib中调整boxplot中框的宽度

转载 作者:太空狗 更新时间:2023-10-29 22:09:09 27 4
gpt4 key购买 nike

我想减少下面箱线图中方框的宽度。这是我的代码,但它不起作用:

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

enter image description here

最佳答案

来自documentation有一个宽度选项:

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.

这是一个例子:

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

关于python - 在python matplotlib中调整boxplot中框的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32443803/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com