y 轴未按比例绘制的箱线图

问题描述 投票:0回答:1

我有一些数据想要绘制箱形图。异常值(例如 20、30)与大多数值(例如 0.0002、0.0003)相差太远,因此当我使用 Matplotlib 绘图时只能看到异常值。

有没有办法放大中位数周围的值,然后让 y 轴的其余部分不按比例显示并显示异常值?

这是我的 Python 代码。我想对我拥有的每个箱线图使用插入轴,如下所示。我怎样才能以简单的方式做到这一点?文档中的示例似乎有太多参数需要处理。

plt.figure()
        ax = plt.subplot(111)
        plt.boxplot(dataToPlot)
        axins = zoomed_inset_axes(ax, 6, loc=1) # zoom = 6
# what follows is taken from example linked in the answer below. 
# I didn't get if the first argument is indeed the data this zoomed image refers to or not. 
        axins.imshow(dataToPlot[1], interpolation="nearest", origin="lower")
# here I only need the y-axis to be in [0,0.1], x-axis is no of use with vertical boxplots
        x1, x2, y1, y2 = -1.5, -0.9, 0.0, 0.1
        axins.set_xlim(x1, x2)
        axins.set_ylim(y1, y2)
        plt.xticks(visible=True)
        plt.yticks(visible=True)
        plt.savefig( 'somewhere.jpeg', bbox_inches=0)
python plot matplotlib boxplot outliers
1个回答
1
投票

我通过添加

sym=''
解决了这个问题,它告诉箱线图不要显示传单(任何超出胡须的东西)。

尝试将问题中的第 3 行更改为:

plt.boxplot(dataToPlot, sym='')
© www.soinside.com 2019 - 2024. All rights reserved.