开发者

matplotlib boxplot color

开发者 https://www.devze.com 2023-03-16 12:47 出处:网络
I\'m trying to create a box & whisker plot of a set of data binning y vers开发者_高级运维us x. I found an useful example in making binned boxplot in matplotlib with numpy and scipy in Python. The

I'm trying to create a box & whisker plot of a set of data binning y vers开发者_高级运维us x. I found an useful example in making binned boxplot in matplotlib with numpy and scipy in Python. The question is now very simple. How can I specify the color of the boxes in matplotlib.pyplot.boxplot as I would like to set it transparent in order to let the reader also to see the original data. I know there exists the example shown in http://matplotlib.sourceforge.net/examples/pylab_examples/boxplot_demo2.html but is anything simpler than this? It looks strange the impossibility to set the color of the boxes directly in boxplot Thank you in advance


You could just render the original data as a scatter plot behind the boxplot and then hide the fliers of the 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()

matplotlib boxplot color

0

精彩评论

暂无评论...
验证码 换一张
取 消