如何更改matplotlib boxp中晶须帽的长度

2024-06-10 07:02:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试更改方框图触须的长度(最小值和最大值点),它们在下图中标记为红色 enter image description here

是否可以在不改变盒子大小的情况下,改变晶须的最小标记和最大标记的长度?在

编辑:我的意思是增加线标记的长度,它表示晶须的最小和最大末端,而不是通过增加置信区间来增加整个晶须本身的长度。在最新更新的图片中,我想增加黑色的最小和最大标记,使其与我用红线指示的尺寸相匹配。在


Tags: 标记编辑尺寸情况图片盒子置信区间黑色
3条回答

在创建方框图时,可以添加参数whis

matplotlib.axes.Axes.boxplot

whis : float, sequence, or string (default = 1.5)
As a float, determines the reach of the whiskers to the beyond the first and  
third quartiles. In other words, where IQR is the interquartile range (Q3-Q1), 
the upper whisker will extend to last datum less than Q3 + whis*IQR). 
Similarly, the lower whisker will extend to the first datum greater than Q1 - 
whis*IQR. Beyond the whiskers, data are considered outliers and are plotted as 
individual points. Set this to an unreasonably high value to force the whiskers 
to show the min and max values. Alternatively, set this to an ascending 
sequence of percentile (e.g., [5, 95]) to set the whiskers at specific 
percentiles of the data. Finally, whis can be the string 'range' to force the
whiskers to the min and max of the data.
fig, axes = plt.subplots(nrows = 1, ncols = 2, figsize=(10, 5))

normal_caps = axes[0].boxplot(s, labels = ['Normal Caps'],
                capprops = dict(linestyle='-', linewidth=2, color='Black'))

big_caps = axes[1].boxplot(s, labels = ['Longer Caps'],
                capprops = dict(linestyle='-', linewidth=2, color='Black'))

for cap in big_caps['caps']:
    cap.set_xdata(cap.get_xdata() + np.array([-.15,.15]))

一些直接来自boxplot example的假数据

# fake up some more data
spread = np.random.rand(50) * 100
center = np.ones(25) * 40
flier_high = np.random.rand(10) * 100 + 100
flier_low = np.random.rand(10) * -100
d2 = np.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

Line2D实例的pyplot.boxplot returns a dictionary中,caps是您想要更改的。这个解决方案将使它们长0.5个x轴单位,设置它们的颜色和线宽。在

^{pr2}$


Artist Tutorial

相关问题 更多 >