python boxplot参数 名称 意义 可选值_python – 在boxplots中覆盖中值/方差的数值

假设您使用boxplot函数绘制箱图,它会返回一个包含图表组件的字典.请注意,该框表示内部四分位数范围(25至75百分位数),而不是标准差.

>>> bp_dict = boxplot(data, vert=False) # draw horizontal boxplot

>>> bp_dict.keys()

>>> bp_dict.keys()

['medians', 'fliers', 'whiskers', 'boxes', 'caps']

它们包含形成每个绘图元素的Line2D对象.您可以使用Line2D.get_xydata方法获取中位数和框位置(在数据坐标中)以确定文本的位置.

from pylab import *

# from http://matplotlib.org/examples/pylab_examples/boxplot_demo.html

# fake up some data

spread= rand(50) * 100

center = ones(25) * 50

flier_high = rand(10) * 100 + 100

flier_low = rand(10) * -100

data =concatenate((spread, center, flier_high, flier_low), 0)

# fake up some more data

spread= rand(50) * 100

center = ones(25) * 40

flier_high = rand(10) * 100 + 100

flier_low = rand(10) * -100

d2 = concatenate( (spread, center, flier_high, flier_low), 0 )

data.shape = (-1, 1)

d2.shape = (-1, 1)

#data = concatenate( (data, d2), 1 )

# Making a 2-D array only works if all the columns are the

# same length. If they are not, then use a list instead.

# This is actually more efficient because boxplot converts

# a 2-D array into a list of vectors internally anyway.

data = [data, d2, d2[::2,0]]

# multiple box plots on one figure

figure()

# get dictionary returned from boxplot

bp_dict = boxplot(data, vert=False)

for line in bp_dict['medians']:

# get position data for median line

x, y = line.get_xydata()[1] # top of median line

# overlay median value

text(x, y, '%.1f' % x,

horizontalalignment='center') # draw above, centered

for line in bp_dict['boxes']:

x, y = line.get_xydata()[0] # bottom of left line

text(x,y, '%.1f' % x,

horizontalalignment='center', # centered

verticalalignment='top') # below

x, y = line.get_xydata()[3] # bottom of right line

text(x,y, '%.1f' % x,

horizontalalignment='center', # centered

verticalalignment='top') # below

show()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值