栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

matplotlib:组箱线图

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

matplotlib:组箱线图

如何使用颜色区分“苹果”和“橙色”以及用空格分隔“ A”,“ B”和“ C”?

像这样:

from pylab import plot, show, savefig, xlim, figure,      hold, ylim, legend, boxplot, setp, axes# function for setting the colors of the box plots pairsdef setBoxColors(bp):    setp(bp['boxes'][0], color='blue')    setp(bp['caps'][0], color='blue')    setp(bp['caps'][1], color='blue')    setp(bp['whiskers'][0], color='blue')    setp(bp['whiskers'][1], color='blue')    setp(bp['fliers'][0], color='blue')    setp(bp['fliers'][1], color='blue')    setp(bp['medians'][0], color='blue')    setp(bp['boxes'][1], color='red')    setp(bp['caps'][2], color='red')    setp(bp['caps'][3], color='red')    setp(bp['whiskers'][2], color='red')    setp(bp['whiskers'][3], color='red')    setp(bp['fliers'][2], color='red')    setp(bp['fliers'][3], color='red')    setp(bp['medians'][1], color='red')# Some fake data to plotA= [[1, 2, 5,],  [7, 2]]B = [[5, 7, 2, 2, 5], [7, 2, 5]]C = [[3,2,5,7], [6, 7, 3]]fig = figure()ax = axes()hold(True)# first boxplot pairbp = boxplot(A, positions = [1, 2], widths = 0.6)setBoxColors(bp)# second boxplot pairbp = boxplot(B, positions = [4, 5], widths = 0.6)setBoxColors(bp)# thrid boxplot pairbp = boxplot(C, positions = [7, 8], widths = 0.6)setBoxColors(bp)# set axes limits and labelsxlim(0,9)ylim(0,9)ax.set_xticklabels(['A', 'B', 'C'])ax.set_xticks([1.5, 4.5, 7.5])# draw temporary red and blue lines and use them to create a legendhB, = plot([1,1],'b-')hR, = plot([1,1],'r-')legend((hB, hR),('Apples', 'Oranges'))hB.set_visible(False)hR.set_visible(False)savefig('boxcompare.png')show()



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/661643.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号