gpt4 book ai didi

numpy - matplotlib 箱线图颜色

转载 作者:行者123 更新时间:2023-12-04 11:29:41 24 4
gpt4 key购买 nike

我正在尝试创建一组数据分箱 y 与 x 的盒须图。我在 making binned boxplot in matplotlib with numpy and scipy in Python 中找到了一个有用的例子.现在的问题很简单。如何在 matplotlib.pyplot.boxplot 中指定框的颜色,因为我想将其设置为透明,以便让读者也能看到原始数据。我知道存在 http://matplotlib.sourceforge.net/examples/pylab_examples/boxplot_demo2.html 中显示的示例但还有比这更简单的吗?无法直接在 boxplot 中设置框的颜色看起来很奇怪
先感谢您

最佳答案

您可以将原始数据渲染为箱线图后面的散点图,然后隐藏箱线图的传单。

import pylab
import numpy

pylab.figure()

data = [numpy.random.normal(i, size=50) for i in xrange(5)]

for x, y in enumerate(data):
pylab.scatter([x + 1 for i in xrange(50)], y, alpha=0.5, edgecolors='r', marker='+')

bp = pylab.boxplot(data)
pylab.setp(bp['boxes'], color='black')
pylab.setp(bp['whiskers'], color='black')
pylab.setp(bp['fliers'], marker='None')

pylab.xlim(0,6)

pylab.show()

enter image description here

关于numpy - matplotlib 箱线图颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6546602/

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